-
Notifications
You must be signed in to change notification settings - Fork 182
Document Terraform (CLI) as a dependency #552
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
Comments
Hi @burck1 For example when you launch any app from the Finder, Dock or Spotlight, they do not automatically inherit your shell environment. See https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x for more. Assuming you are confident that launchd knows about If that still doesn't work, I would suggest you to try installing Terraform under a path which is known to launchd:
Personally I use Homebrew to manage most of the software on my macOS and HashiCorp also provides official tap you can use to install Terraform from: https://github.com/hashicorp/homebrew-tap Homebrew installs binaries under As for your other issue in the LS repository I will leave it open, because I think we could do better job in the error messaging there, perhaps even consider printing out the |
Hi @radeksimko. I added In my scenario, since I am using zsh as my primary shell environment and added the Note: Running
Though adding
|
That is a good point. We should make that more obvious. Relatedly we have also discussed the option of prompting the user to install Terraform automatically via click of a button to a temp folder, similar to how the extension installs the language server.
This is already possible today via settings, see https://github.com/hashicorp/vscode-terraform/wiki/Manually-Setting-the-Terraform-Executable-Path
I would be curious to know how you manage these different installations of Terraform locally. Would you just I imagine this is a common problem for someone who manages multiple projects and so understanding your workflow would help us support it better. I'm aware some people use tfenv to deal with this problem and the language server should be able to pick it up automatically, although there are some currently known challenges with tfenv: |
This comment has been minimized.
This comment has been minimized.
Not OP, but I can chime in. For switching terraform versions we've settled on Terraform Switcher. tfswitch swaps /usr/local/bin/terraform symlinks around instead of adding shims into the PATH. Each of our workspaces and modules contain a .terraform-version file to facilitate switching to the correct terraform version. Looks like tfswitch also supports checking the |
Sorry for the delayed response. We do something very similar to what @bevans-HD mentions. We commit a config file to our repos that specifies the terraform version to be used (among other CI / CD) settings. Then we've developed in-house wrapper around the terraform CLI that handles switching the terraform version used based on the config file (looks for the config file recursively in parent directories). But for a more universal option, my suggestion for the vscode terraform extension would be to support the standard vscode extension workspace configuration settings that can be committed to our repos. Something along the lines of:
Though it looks like we can override the terraform executable path, it'd be nice if the extension would handle downloading and switching it for us. Furthermore, if this extension supported Multi-root Workspaces then we'd be able to setup each terraform configuration root in our repos with separate vscode settings and thus potentially separate terraform versions. |
I would also like to add to this another tool version system called asdf which does add shims. Installing terraform from homebrew is honestly a very naive thing as there are very good use cases where you need multiple versions of Terraform as @burck1 mentioned. When trying to override the path, however, it just crashes as it uses a shim and isn't a link to a binary. |
@blairham This is very useful feedback.
The dependency on Terraform is largely a dependency of the language server itself, so from extension perspective a transitive one. There is currently some logic which does run Terraform CLI directly, but the overall aim is to keep such surface (direct communication between the extension and Terraform) minimal. Generally having one entry point is beneficial from all perspectives and that is the ultimate goal and also one of the reasons we maintain a language server. Therefore if we are to somehow integrate with such tool and support it better it would be mostly on the language server side, or more specifically in TL;DR The best place to track this feedback would be in hashicorp/terraform-exec#6 or hashicorp/terraform-ls#305
I believe this is related to the fact that the language server currently doesn't parse the flag value in any special way, as I also mentioned here: hashicorp/terraform-ls#128 (comment) Unfortunately I haven't had much capacity available lately to improve mattn/go-shellwords#39 in any way. If you are willing to jump in with some Powershell experience you are more than welcomed. |
This comment has been minimized.
This comment has been minimized.
I'm going to re-open this until we document the optional dependency, probably under https://github.com/hashicorp/vscode-terraform#code-formatting |
btw. you can also use tenv that support Terraform as well as OpenTofu (and Terragrunt :) ) in one tool. It allow you to simplify version management and can do much more, than tfswitch. |
I've also filed this as a bug for the terraform-ls repo: hashicorp/terraform-ls#398
OS: Darwin x64 20.2.0 (macOS Big Sur Version 11.1)
VS Code: 1.53.0
VS Code Terraform Extension: v2.5.0
The VS Code Terraform extension always gives me the following message whenever I open any
.tf
file.Then although I have already run
terraform init
, when I click the terraform init button I get the following message.I was able to replicate this error when opening VS Code into a folder with a single minimal
main.tf
file.File Tree
main.tf
terraform version
outputterraform init
outputterraform-ls logs output for the terraform VSCode extension. For this output:
main.tf
which gave me the message in the first screenshotterraform init
button in the popup messageTerraform Install
I simply downloaded and extracted the terraform executable to
~/.local/bin
. Then I added~/.local/bin
to my PATH via my~/.zshrc
usingexport PATH="$HOME/.local/bin:$PATH"
The text was updated successfully, but these errors were encountered: