Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: auto completion of command arguments #28788

Open
tyki6 opened this issue May 24, 2021 · 8 comments
Open

cli: auto completion of command arguments #28788

tyki6 opened this issue May 24, 2021 · 8 comments

Comments

@tyki6
Copy link

tyki6 commented May 24, 2021

Output shell completion code for the specified shell (bash or zsh). The shell code must be evaluated to provide
interactive completion of terraform commands. This can be done by sourcing it from the .bash_profile.

Current Terraform Version

Terraform Version: Terraform v0.14.10

Use-case

Like kubectl completion bash or helm completion, completion code for the specified shell when you press tab shell propose you all possibility.
Example:

terraform
init validate plan apply destroy

terraform state rm module.
exemple example2 example3

Attempted Solutions

Proposal

References

@tyki6 tyki6 added enhancement new new issue not yet triaged labels May 24, 2021
@jbardin
Copy link
Member

jbardin commented May 24, 2021

Hi @mbouamama,

Terraform has the ability to autocomplete the commands available, and can add the basic shell configuration documented here: https://www.terraform.io/docs/cli/commands/index.html#shell-tab-completion

Terraform however cannot autocomplete the possible arguments to commands as you have shown in the second example, so we can leave this open for a possible future enhancement.

@jbardin jbardin changed the title Auto completion cli: auto completion of command arguments May 24, 2021
@jbardin jbardin added cli and removed new new issue not yet triaged labels May 24, 2021
@tyki6
Copy link
Author

tyki6 commented May 24, 2021

Oh sorry next time i will check documentation before opened an issue.
Yes it's will be a nice feature to have auto completion of command argument.If it's ok for you i will create a pr for that.

@apparentlymart
Copy link
Contributor

Hi @mbouamama,

We have previously experimented with implementing completion for arguments to Terraform's subcommands, and the terraform workspace subcommands show an example of that completing workspace names, but ultimately we learned that the current structure of Terraform's CLI layer is not correct in order to implement argument completion in a maintainable way, and so we want to refactor how we process command line arguments before investing further in completion. If we implement completion in a less-maintainable first and then refactor then it would make the refactoring harder.

For that reason, I don't expect that we would accept PRs to add new completion features at the moment, but as @jbardin said we'll use this issue to represent the request for more completion, which we'll consider along with all of the other feature requests in future releases. Completing a new design for how Terraform represents and processes its own arguments is a prerequisite for any more work on this particular issue, though.

@magodo
Copy link
Contributor

magodo commented Oct 29, 2021

@apparentlymart I've just submit a PR to add the supports for auto-completing the resource addresses for a couple of commands in #29828, right before seeing this issue 😅

I'd admit that the PR has some duplication of the code from the implementation of terraform state list (similar to what terraform workspace select has been doing). While I still feel that should be fine for now and it actually works well (from my personal feeling). WDYT?

@yermulnik
Copy link

@apparentlymart Apologies for bumping old issue, though has there been any update on this? Or any roadmap/plans on implementation? Thanks.

@crw
Copy link
Collaborator

crw commented Nov 4, 2022

@yermulnik This is not currently on the roadmap. Please do use the 👍 reaction on the original description to help promote this issue in the future.

@obvionaoe
Copy link

It'd be great if completion generation a la kubectl could be added, where if we run:

kubectl completion <shell_name>

it generates a native completion script for the provided shell and we can put it in the appropriate directory.

@subrossa
Copy link

subrossa commented Mar 29, 2023

Hi @jbardin
I have installed autocompletion to git bash with the command terraform -install-autocomplete and restarted shell.
The following content is written to ./bashrc file complete -C C:\Program Files\Terraform\terraform.exe terraform.exe,
but still, terraform commands autocompletion doesn't work.
When typing terraform p and pressing Tab, I'm expecting to get terraform commands suggestions like plan, but I'm getting the list of files in the directory starting with p letter. Not sure what am I missing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants