terraform icon indicating copy to clipboard operation
terraform copied to clipboard

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

Open artiphishle opened this issue 1 year ago • 3 comments

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 avatar Jul 12 '24 05:07 artiphishle

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

artiphishle avatar Jul 12 '24 05:07 artiphishle

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!

apparentlymart avatar Jul 12 '24 18:07 apparentlymart

Looks like this was originally raised here as issue #25421 in June 2020. The corresponding pull request in the upstream repository linked there is https://github.com/posener/complete/pull/124.

For what it's worth, this is still reproducible with the latest version of Terraform (1.12.1) on the latest Mac OS (15.5). The workaround described in the original issue (of manually adding the missing line to .zshrc) still works.

DavidShepherdson avatar Jun 10 '25 04:06 DavidShepherdson