vscode-terraform icon indicating copy to clipboard operation
vscode-terraform copied to clipboard

Extension complaining Terraform CLI is not installed when it is

Open DrStrangepork opened this issue 4 years ago • 12 comments
trafficstars

I installed v2.9.1 of the extension. When VSCode window launches, I get the notification:

Terraform (CLI) is required. Please install Terraform or make it available in $PATH

However, I have terraform installed to /usr/local/bin which is in both my $PATH and in $PATH for root, so I don't know why it reports it as not being there

# ls -l `which terraform`
-rwxr-xr-x 1 n0304144 82171776 Jan  6 14:21 /usr/local/bin/terraform

DrStrangepork avatar Apr 01 '21 14:04 DrStrangepork

I copied the terraform executable into ~/.local/bin as well, and that didn't fix it.

DrStrangepork avatar Apr 01 '21 15:04 DrStrangepork

Hi @DrStrangepork -- sorry you're hitting that issue! Can you tell us what platform you're on? It would also be useful to see your logs (details on how to do that).

aeschright avatar Apr 01 '21 23:04 aeschright

It's the same bug for me. When installing an older version like 2.9.0 it magically starts working! When I'm installing 2.9.1 it's doesn't work.

Edit. The best version where everything works is 2.8.3

KamGor avatar Apr 02 '21 13:04 KamGor

I ran the manual logging command, reloaded VSCode and got the same error again. Here is the log:

2021/04/02 11:39:55 serve_command.go:101: Terraform executions will be logged to /tmp/tf-exec-{{lsPid}}-{{args}}.log (interpolated at the time of execution)
2021/04/02 11:39:55 serve_command.go:137: Starting terraform-ls 0.15.0
2021/04/02 11:39:55 service.go:71: Preparing new session ...
2021/04/02 11:39:55 watcher.go:219: watching for changes ...
2021/04/02 11:39:55 langserver.go:69: Starting server (pid 93336) ...

DrStrangepork avatar Apr 02 '21 15:04 DrStrangepork

After keeping that logging command running for a couple of workdays, there was no additional information added.

Installing version 2.8.3 fixed the problem for me as well.

DrStrangepork avatar Apr 07 '21 15:04 DrStrangepork

It's puzzling that downgrading the extension addressed the issue for you -- the error you're seeing is coming from the language server, which is on its own release cycle. Here's the discussion from a similar issue that was reported: https://github.com/hashicorp/vscode-terraform/issues/552#issuecomment-775037784

Can we give this a try? Set the Terraform path manually in the extension settings and upgrade to the newest extension version.

aeschright avatar Apr 08 '21 19:04 aeschright

I had the same problem. Setting the terraform path manually worked around it for me.

I've seen signs with other bits of VSCode that something in a recent release has made it fail to pick up env var changes, esp PATH, from my shell environment (Linux here), where that used to work reliably. So any PATH elements setup by my .bashrc are a toss-up whether a given launch of VSCode sees them.

Edit: and in case it wasn't clear from that, my terraform binary is in ~/bin/ which gets added to PATH by my .bashrc. I'm guessing the OP's ~/.local/bin/ is in the same boat

mgabeler-lee-6rs avatar Apr 26 '21 19:04 mgabeler-lee-6rs

Edit: and in case it wasn't clear from that, my terraform binary is in ~/bin/ which gets added to PATH by my .bashrc. I'm guessing the OP's ~/.local/bin/ is in the same boat

It's worth noting that it doesn't matter what's in your .bashrc unless you actually launch VSCode from your terminal window - which may not be very common for e.g. macOS users. VSCode launched from Finder, Spotlight, or Dock will not inherit any variables you may have set for your shell.

radeksimko avatar Apr 26 '21 19:04 radeksimko

VSCode launched from Finder, Spotlight, or Dock will not inherit any variables you may have set for your shell

This totally used to work. I have about fifty build & launch configs that worked for years, and have only started breaking since the last release or two of vscode due to this issue.

I realize this isn't the terraform extension's issue however

Edit: also I don't use macOS, though many of my coworkers do

mgabeler-lee-6rs avatar Apr 26 '21 20:04 mgabeler-lee-6rs

I always get this error when my machine just restarted and VSCode is automatically open (I use that option to remember what you have open before shutting down). My workaround is to use the command palette and reload VSCode, and in the second time it works.

VSCode launched from Finder, Spotlight, or Dock will not inherit any variables you may have set for your shell

Even if this is true, then I'd say that the Terraform extension should try to load them manually. This is the only extension that breaks like this, and a lot of other extensions rely on my Shell variables to work (e.g stuff picking my Node version that comes from NVM).

rdsedmundo avatar May 05 '21 09:05 rdsedmundo

Even if this is true, then I'd say that the Terraform extension should try to load them manually. This is the only extension that breaks like this, and a lot of other extensions rely on my Shell variables to work (e.g stuff my Node version that comes from NVM).

I would be curious to see if any extension attempts to add/replace parts of $PATH. Do you have a link to any extension which does this?

In general though I don't see how any extension could in practice read shell variables, other than basically re-implementing OS behaviours. As far as I'm aware VS Code itself has to be launched with certain environment variables already and extension just inherit these - they may choose to override it of course, but I'd assume if they do then it's to a static value provided by the user via configuration or something like that.

What might be happening with NVM is that NVM is placing relevant binaries in $PATH which is already being passed down to VS Code upon launch.

I would be curious where/how did you install Terraform and what OS are you on? Maybe we (also) need to improve docs in that area to encourage folks to install in path which is already contained within $PATH passed down to VS Code by default. We're generally working within the constraints of the ways people can install Terraform today though - e.g. we don't own/control tfenv and where it installs binaries, or where people manually place their binaries after downloading them via browser.

Personally I'm not opposed to adding a config option for $PATH, although I'd much rather see things working out of the box for most people, so understanding the problem is as important as having a work around.

radeksimko avatar May 05 '21 10:05 radeksimko

I installed Terraform using brew.

I actually did a couple of tests now by quitting VSCode completely (force quit via Activity Monitor) then tried to open it via Spotlight and also via Dock. Both ways worked and Terraform was recognized. So, in my case, this is only an issue when the MacOS restores the system.

Seems like someone reported something along those lines, but unfortunately it was closed without resolution: https://github.com/microsoft/vscode/issues/44060

rdsedmundo avatar May 05 '21 11:05 rdsedmundo