terraform -install-autocomplete not working on stock macOS Catalina 10.15.5 with default zsh shell

Created on 27 Jun 2020  ยท  4Comments  ยท  Source: hashicorp/terraform

Hi Everyone

I'm having trouble enabling autocompletion on a fresh MacOS terraform install.

Here are the details of the versions I'm running:

OS: macOS Catalina Version 10.15.5
Terminal App: Terminal (default)
Shell: zsh 5.7.1 (x86_64-apple-darwin19.0) (default)
Terraform version: v0.12.28
Path to terraform binary: /usr/local/bin/terraform

At first running the command terraform -install-autocomplete would return:

Error executing CLI: Did not find any shells to install

I noticed that on a fresh OS install there was no .zshrc file in my home directory, so I created one with touch ~/.zshrc and re-ran terraform -install-autocomplete.

This resulted in adding the following to my ~/.zshrc file:

autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /usr/local/bin/terraform terraform

So I restarted my zsh session and autocomplete does not work. There is an error message that appears beneath the login banner:

complete:13: command not found: compdef

I can work around this by changing my default shell back to Bash, running terraform -uninstall-autocomplete, touching a ~/.profile file and running terraform -install-autocomplete again, but I'd like to use zsh since bash is now deprecated on MacOS.

Kind Regards,

Ben

upstream v0.12

Most helpful comment

Proposed a change to the zsh.go script in @posener 's complete library that Terraform depends on:
https://github.com/posener/complete/pull/124
Added check for the autoload -Uz compinit && compinit line in zsh config.

All 4 comments

This error indicates that your zsh configuration doesn't have autocomplete enabled. You can do this by adding the following lines to the top of your ~/.zshrc (before the Terraform completion lines):

autoload -Uz compinit
compinit

Once that's done, exec zsh or logging out/in should clear this error and enable Terraform completion. Hope that helps!

That worked a treat, thanks @alisdair!

Looks like the install-autocomplete script could do with a check to see if that line is present in .zshrc or not. I'll have a dig for it in the terraform github and propose a change.

For anyone else looking to solve this problem, here is my working .zshrc:

autoload -U +X bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -o nospace -C /usr/local/bin/terraform terraform

Proposed a change to the zsh.go script in @posener 's complete library that Terraform depends on:
https://github.com/posener/complete/pull/124
Added check for the autoload -Uz compinit && compinit line in zsh config.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings