hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.02k stars 9.47k forks source link

.zshrc not correct autofilled when installing using brew on macos. #35450

Open artiphishle opened 1 month ago

artiphishle commented 1 month ago

Terraform Version

Terraform v1.5.7
on darwin_arm64

Your version of Terraform is out of date! The latest version
is 1.9.2. You can update by downloading from https://www.terraform.io/downloads.html

Issue & Solution proposal

It's not possible to source ~/.zshrc anymore due to:

complete:13: command not found: compdef

The solution like mentioned in the stackoverflow link at the bottom to add this line missing:

autoload -Uz compinit && compinit

The whole .zshrc content should therefore be:

autoload -Uz compinit && compinit # this one was missing
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /opt/homebrew/bin/terraform terraform

https://stackoverflow.com/questions/66338988/complete13-command-not-found-compdef

Steps to Reproduce

  1. Install terraform using brew
  2. Install terraform autocomplete (maybe optional)
  3. source ~/.zshrc (or open new terminal)

Additional Context

just figured that my terraform isn't up-to-date, so the current version isn't available by installing using brew? Just installed 30mins ago, therefore expecting a new version.

artiphishle commented 1 month ago

Maybe comes due to terraform -install-autocomplete and not by the installation itself. Just read the supplied stackoverflow link for details, thanks.

apparentlymart commented 1 month ago

Thanks for reporting this, @artiphishle.

Indeed, Terraform will not modify your shell configuration except when running with the -install-autocomplete option, so that'll be needed for someone to reproduce this. They'll also need to create the right circumstances for that option to decide that it should install for zsh as opposed to any other shell.

Terraform inherits this functionality from upstream dependencies, at two levels:

zsh in particular is handled using zsh.install, which in the latest commit upstream seems to add the following to .zshrc:

autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /opt/homebrew/bin/terraform terraform

As reported, this does not include autoload -Uz compinit && compinit. To include that would require a change to the upstream library.

I can't find any existing issue or PR in the github.com/posener/complete repository, so I expect we'll need to open something there once we've confirmed the problem.

Thanks again!