terraform icon indicating copy to clipboard operation
terraform copied to clipboard

cli: auto completion of command arguments

Open tyki6 opened this issue 3 years ago • 5 comments

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 avatar May 24 '21 13:05 tyki6

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 avatar May 24 '21 14:05 jbardin

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.

tyki6 avatar May 24 '21 14:05 tyki6

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.

apparentlymart avatar May 26 '21 18:05 apparentlymart

@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 :sweat_smile:

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?

magodo avatar Oct 29 '21 07:10 magodo

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

yermulnik avatar Oct 21 '22 17:10 yermulnik

@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.

crw avatar Nov 04 '22 00:11 crw