vscode-terraform: "Workspace not initialized" error when vscode is opened from a superdirectory

terraform version: 0.12.24 terraform-vscode: 2.0.1 os: ubuntu 20.04

I am running vscode that contains multiple repos and directories. A few directory levels beneath, there is a terraform workspace.

Actual Behavior

[Error - 10:01:22 PM] Server initialization failed. Message: Workspace not initialized. Please run terraform init in /vscode/workspace/path Code: -32098

Expected Behavior:

Language server automatically being able to detect the terraform workspace in one of the subdirectories, OR having the ability to define it in the Global or Workspace specific settings json, for example, something like:

"terraform.languageServer": {
    "args": [
      "serve",
      "-tf-workspace=path/to/workspace",
    ]
}

Similar to https://github.com/hashicorp/vscode-terraform/issues/329 but this one assumes that vs workspace is >= 1 levels above the root terraform workspace.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 69
  • Comments: 27 (1 by maintainers)

Most upvoted comments

Same here. Terraform configuration is not in the root but in a sub directory as the Terraform code is just part of the wohle project. This problem makes the extension actually useless for all my projects now. ☹

What makes it even worse it that this new behavior is not noted anywhere in the release notes. Furthermore no real workaround seems to be available, right now. The previous version (still from Mikael Olenfalk) had no problem whit that and worked perfectly in my projects/workspaces. But now after the automatically update to the new version it is completely broken (no code completion, no proper syntax highlighting and no formatting anymore) without any warning forehand. 🤬

I do not know what has changed that the behavior is now that different but it makes the current version of the extension worse that the previous! So please fix that immediately.

Please also understand that very often the Terraform code is part of a whole project and the project consists not only of some .tf files in the root. (Apart some very simple, not real world, examples maybe.) So the extension must support that out of the box.

Agreeing with the above sentiments. Pre-2.0.0 the language server crashed occasionally but otherwise was auto-formatting and auto-completing my 0.12 definitions. I almost exclusively have my Terraform in infra/ subdirectories of my workspace or have multiple Terraform installations in a single workspace, so this update has disrupted my preferred

100%

i cannot believe this was pushed out without consideration of using TF in subdirectories. SMH

@dimisjim

Make sure you run terraform init from the root of your project opening vscode (that should do it). also, here’s a small snippet of my terraform-ls.tf:

#
# Providers Config -------------------------------------------------------------
#

provider "null" {
  version = "~> 2.0"
}

provider "template" {
  version = "~> 2.0"
}

provider "aws" {
  version = "~> 2.0"
  region = "us-east-1"
}

provider "datadog" {
  version = "~> 2.5"
}

provider "github" {
  version = "~> 2.8"
}

Previous extension version was also not working (at least for tf v0.12). I used it for having simple color code formatting for the .tf files, so by disabling it again, it basically has the same functionality as before now.

previous version worked just fine for me with 0.12

Agreeing with the above sentiments. Pre-2.0.0 the language server crashed occasionally but otherwise was auto-formatting and auto-completing my 0.12 definitions. I almost exclusively have my Terraform in infra/ subdirectories of my workspace or have multiple Terraform installations in a single workspace, so this update has disrupted my preferred layout.

That’s bizarre. The reason why the language server project was created and the whole point of this ongoing development was that the existing extension did not support hcl2 (tf 0.12.x)

What features were working in the previous version for you?

@dimisjim more like what wasnt! everything worked fine. auto complete, error detection, linting, fmt. everything

v2 doesnt work. period have to follow https://github.com/hashicorp/vscode-terraform/issues/372 to downgrade

Also experiencing this, would be really handy to have an option to specify the directory where the Terraform scripts are.

where the previous dev kept releasing updates to the LS and the extension

ok I might have missed it then and assumed it was never really there as it was never officially released and always deemed experimental by the developers themselves.

In any case, it doesn’t change the fact that the current 2.0.1 is more like 0.0.1 than 2.x.x

Previous extension version was also not working (at least for tf v0.12). I used it for having simple color code formatting for the .tf files, so by disabling it again, it basically has the same functionality as before now.

Same issue here, my work has a Terraform monorepo for all of our IaC. I tried adding the reistered_providers fix mentioned at the top of #329, and it stopped the error, but the Language Server still won’t give me any completions