Skip to content
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

"Workspace not initialized" error when vscode is opened from a superdirectory #366

Closed
dimisjim opened this issue Jun 10, 2020 · 27 comments
Closed

Comments

@dimisjim
Copy link

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 #329 but this one assumes that vs workspace is >= 1 levels above the root terraform workspace.

@rauvolaj
Copy link

same issue as above, and my folder structure follows this comment in #329

@moskyb
Copy link

moskyb commented Jun 10, 2020

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

@J0F3
Copy link

J0F3 commented Jun 11, 2020

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.

@ciaransweet
Copy link

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

@dimisjim
Copy link
Author

dimisjim commented Jun 11, 2020

@J0F3 You can disable it for now by setting the external flag in the settings json to false

"terraform.languageServer": {
    "external": false,
    "args": [
      "serve",
      "-tf-exec=/opt/hashicorp/terraform",
    ]
}

@J0F3
Copy link

J0F3 commented Jun 11, 2020

@dimisjim Yes, I know. But does not help me either. I do not want do disable the language server. The point is, that I had a working Terraform 0.12 support in VS Code with the extension and now, since the new version, the extension does basically not work in any of my projects anymore.
If I have to disable the language Server I do not see much advantage of this extension anymore. 😉

@dimisjim
Copy link
Author

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.

@FernandoMiguel
Copy link

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

@dimisjim
Copy link
Author

@FernandoMiguel

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?

@FernandoMiguel
Copy link

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

@FernandoMiguel
Copy link

all you had to do was to follow #157

@dimisjim
Copy link
Author

You are referring to a huge issue thread.

What exactly did you have to follow for it to work perfectly?
Because from the comments in it, it was quite clear that the support was buggy and by no means complete. Otherwise why wasn't the issue closed and officially released in the vs marketplace?

@FernandoMiguel
Copy link

You are referring to a huge issue thread.

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

What exactly did you have to follow for it to work perfectly?

error detection, linting, fmt.
lint is now disabled due to not supporting tflint #337

but to not flag broken resources? not be able to fmt my code automatically on save?
to totally fail to init, to not work if it is in a subdir (this very own issue)

@dimisjim
Copy link
Author

dimisjim commented Jun 11, 2020

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

@FernandoMiguel
Copy link

v2 doesnt work. period
have to follow #372 to downgrade

@taiidani
Copy link

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.

@georgegil
Copy link

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

@nbetm
Copy link

nbetm commented Jun 11, 2020

I understand everyone's frustration (I'm one), but as it's stated here the new module/terraform-ls does not support nested modules (sub-dirs).

That being said, I found a very simple workaround that works well for me. I added a single terraform-ls.tf file at the root of the project containing only the list of providers I regular use.

I believe that's what terraform-lsp inside your ~/.vscode/... directory.

@dimisjim
Copy link
Author

@nbetm

tried it, getting same error

@nbetm
Copy link

nbetm commented Jun 11, 2020

@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"
}

@dimisjim
Copy link
Author

Ok works this way, but you still get this annoying change of focus in the output tab down below, basically this: #371

@nbetm
Copy link

nbetm commented Jun 11, 2020

@dimisjim, I haven't run into the annoying change of focus in the output tab yet. but I will be writing some code later today. I will share my final experience with the server being enabled!

@barneyparker
Copy link

@nbetm This does work - its a bit of a hack, but i'll do for now! 👍

@opub
Copy link

opub commented Jun 15, 2020

There is a "Terraform (forked)" extension (l2fprod.terraform-fork v1.4.28) by Frederic Lavigne that seems to be a fork of Mikael Olenfalk's v.1.4 release. I have switched to this until this issue or the upstream version pinning issue are fixed.

@jongio
Copy link

jongio commented Jun 16, 2020

Confirming that this: #366 (comment) works as a stopgap

@paultyng
Copy link
Contributor

Going to close this to merge in with the existing initalization issues or the main folder structure issue: hashicorp/terraform-ls#32 (comment)

@ghost
Copy link

ghost commented Jul 16, 2020

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 context necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests