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 #329

Closed
smiller171 opened this issue Jun 4, 2020 · 56 comments
Closed

Workspace not initialized #329

smiller171 opened this issue Jun 4, 2020 · 56 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@smiller171
Copy link

smiller171 commented Jun 4, 2020

Workaround:

For anyone who comes across this issue, as long as your TF is in the root of your project, you're likely seeing this issue within a child module that doesn't declare it's own providers, instead relying on inheritance from a parent module. If this is the case, a workaround that works for me is to define the required_providers so that Terraform knows what providers to cache when you init.

example:

terraform {
  required_providers {
    aws = "~> 2.61.0"
  }
}

Original issue description:

When trying to enable the language server with the new 2.0.0-rc1 version, I get a "Workspace not initialized" error, which is not resolved by running terraform init

Workspace not initialized. Please run `terraform init` in /Users/smiller/code/terraform-anycloud-template
Launching language server: /Users/smiller/.vscode/extensions/hashicorp.terraform-2.0.0-rc.1/lsp/terraform-ls serve
2020/06/04 15:37:53 service.go:63: Preparing new session ...
2020/06/04 15:37:53 langserver.go:79: Starting server (pid 53425) ...
2020/06/04 15:37:53 server.go:469: Received 1 new requests
2020/06/04 15:37:53 server.go:165: Processing 1 requests
2020/06/04 15:37:53 server.go:223: Checking request for "initialize": {"processId":52705,"rootPath":"/Users/smiller/code/terraform-anycloud-template","rootUri":"file:///Users/smiller/code/terraform-anycloud-template","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/smiller/code/terraform-anycloud-template","name":"terraform-anycloud-template"}]}
2020/06/04 15:37:53 rpc_logger.go:29: Incoming request for "initialize" (ID 0): {"processId":52705,"rootPath":"/Users/smiller/code/terraform-anycloud-template","rootUri":"file:///Users/smiller/code/terraform-anycloud-template","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/smiller/code/terraform-anycloud-template","name":"terraform-anycloud-template"}]}
2020/06/04 15:37:53 exec.go:182: Starting /usr/local/bin/terraform ["terraform" "version"] in "/var/folders/43/thr3y6c55s718zjvk__hcns4hg_30g/T/"...
2020/06/04 15:37:53 exec.go:148: Waiting for command to finish ...
2020/06/04 15:37:54 exec.go:174: terraform run (/usr/local/bin/terraform ["terraform" "version"], in "/var/folders/43/thr3y6c55s718zjvk__hcns4hg_30g/T/", pid 53426) finished with exit code 0
2020/06/04 15:37:54 initialize.go:90: Found compatible Terraform version (0.12.26) at /usr/local/bin/terraform
2020/06/04 15:37:54 schema_storage.go:334: Adding workspace for watching: "/Users/smiller/code/terraform-anycloud-template"
2020/06/04 15:37:54 watcher.go:88: Adding "/Users/smiller/code/terraform-anycloud-template/.terraform/plugins/darwin_amd64/lock.json" for watching...
2020/06/04 15:37:54 schema_storage.go:124: Acquiring semaphore before retrieving schema for "/Users/smiller/code/terraform-anycloud-template" ...
2020/06/04 15:37:54 schema_storage.go:133: Retrieving schemas for "/Users/smiller/code/terraform-anycloud-template" ...
2020/06/04 15:37:54 exec.go:182: Starting /usr/local/bin/terraform ["terraform" "providers" "schema" "-json"] in "/Users/smiller/code/terraform-anycloud-template"...
2020/06/04 15:37:54 rpc_logger.go:45: Error for "initialize" (ID 0): [-32098] Workspace not initialized. Please run `terraform init` in /Users/smiller/code/terraform-anycloud-template
2020/06/04 15:37:54 server.go:204: Completed 1 requests [1.091489042s elapsed]
[Error - 3:37:54 PM] Server initialization failed.
  Message: Workspace not initialized. Please run `terraform init` in /Users/smiller/code/terraform-anycloud-template
  Code: -32098 
2020/06/04 15:37:54 server.go:469: Received 1 new requests
2020/06/04 15:37:54 exec.go:148: Waiting for command to finish ...
2020/06/04 15:37:54 server.go:165: Processing 1 requests
2020/06/04 15:37:54 server.go:223: Checking request for "shutdown": 
2020/06/04 15:37:54 rpc_logger.go:29: Incoming request for "shutdown" (ID 1): 
2020/06/04 15:37:54 rpc_logger.go:50: Response to "shutdown" (ID 1): null
2020/06/04 15:37:54 server.go:204: Completed 1 requests [132.937µs elapsed]
2020/06/04 15:37:54 server.go:469: Received 1 new requests
2020/06/04 15:37:54 server.go:165: Processing 1 requests
2020/06/04 15:37:54 server.go:223: Checking request for "exit": 
2020/06/04 15:37:54 rpc_logger.go:29: Incoming notification for "exit": 
2020/06/04 15:37:54 schema_storage.go:116: error obtaining schemas: Unable to retrieve schemas: failed to get schemas: Execution of ["terraform" "providers" "schema" "-json"] canceled.
signal: killed
@paultyng
Copy link
Contributor

paultyng commented Jun 4, 2020

Yes, we plan to add an initialization workflow where the extension prompts. We can use this as the tracking issue (I'm still working my way through issue cleanup and creation).

@paultyng paultyng closed this as completed Jun 4, 2020
@paultyng paultyng reopened this Jun 4, 2020
@paultyng paultyng added this to the v2.1.0 milestone Jun 4, 2020
@matt-forster
Copy link

matt-forster commented Jun 4, 2020

I'm also getting a similar error for a multi-repository workspace. One repo is not a terraform project, and the other repo has multiple terraform root folders within it (terraform mono-repo?).

Launching language server: /Users/matt/.vscode/extensions/hashicorp.terraform-2.0.0-rc.1/lsp/terraform-ls serve
2020/06/04 14:28:50 service.go:63: Preparing new session ...
2020/06/04 14:28:50 langserver.go:79: Starting server (pid 81445) ...
2020/06/04 14:28:50 server.go:469: Received 1 new requests
2020/06/04 14:28:50 server.go:165: Processing 1 requests
2020/06/04 14:28:50 server.go:223: Checking request for "initialize": {"processId":81211,"rootPath":"/Users/matt/non-terraform-project","rootUri":"file:///Users/matt/non-terraform-project","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/matt/non-terraform-project","name":"images"},{"uri":"file:///Users/matt/terraform-project","name":"operations"}]}
2020/06/04 14:28:50 rpc_logger.go:29: Incoming request for "initialize" (ID 0): {"processId":81211,"rootPath":"/Users/matt/non-terraform-project","rootUri":"file:///Users/matt/non-terraform-project","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}}},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true}}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/matt/non-terraform-project","name":"images"},{"uri":"file:///Users/matt/terraform-project","name":"operations"}]}
2020/06/04 14:28:50 exec.go:182: Starting /Users/matt/.asdf/shims/terraform ["terraform" "version"] in "/var/folders/_m/2vc1tn9j7ng2d5kwkqs73zz80000gn/T/"...
2020/06/04 14:28:50 exec.go:148: Waiting for command to finish ...
2020/06/04 14:28:51 exec.go:174: terraform run (/Users/matt/.asdf/shims/terraform ["terraform" "version"], in "/var/folders/_m/2vc1tn9j7ng2d5kwkqs73zz80000gn/T/", pid 81446) finished with exit code 0
2020/06/04 14:28:51 initialize.go:90: Found compatible Terraform version (0.12.21) at /Users/matt/.asdf/shims/terraform
2020/06/04 14:28:51 schema_storage.go:334: Adding workspace for watching: "/Users/matt/non-terraform-project"
2020/06/04 14:28:51 watcher.go:88: Adding "/Users/matt/non-terraform-project/.terraform/plugins/darwin_amd64/lock.json" for watching...
2020/06/04 14:28:51 schema_storage.go:124: Acquiring semaphore before retrieving schema for "/Users/matt/non-terraform-project" ...
2020/06/04 14:28:51 schema_storage.go:133: Retrieving schemas for "/Users/matt/non-terraform-project" ...
2020/06/04 14:28:51 exec.go:182: Starting /Users/matt/.asdf/shims/terraform ["terraform" "providers" "schema" "-json"] in "/Users/matt/non-terraform-project"...
2020/06/04 14:28:51 rpc_logger.go:45: Error for "initialize" (ID 0): [-32098] Workspace not initialized. Please run `terraform init` in /Users/matt/non-terraform-project
2020/06/04 14:28:51 server.go:204: Completed 1 requests [234.295811ms elapsed]
[Error - 2:28:51 PM] Server initialization failed.
  Message: Workspace not initialized. Please run `terraform init` in /Users/matt/non-terraform-project
  Code: -32098 
2020/06/04 14:28:51 exec.go:148: Waiting for command to finish ...
2020/06/04 14:28:51 server.go:469: Received 1 new requests
2020/06/04 14:28:51 server.go:165: Processing 1 requests
2020/06/04 14:28:51 server.go:223: Checking request for "shutdown": 
2020/06/04 14:28:51 rpc_logger.go:29: Incoming request for "shutdown" (ID 1): 
2020/06/04 14:28:51 rpc_logger.go:50: Response to "shutdown" (ID 1): null
2020/06/04 14:28:51 server.go:204: Completed 1 requests [159.085µs elapsed]
2020/06/04 14:28:51 server.go:469: Received 1 new requests
2020/06/04 14:28:51 server.go:165: Processing 1 requests
2020/06/04 14:28:51 server.go:223: Checking request for "exit": 
2020/06/04 14:28:51 rpc_logger.go:29: Incoming notification for "exit": 
2020/06/04 14:28:51 schema_storage.go:116: error obtaining schemas: Unable to retrieve schemas: failed to get schemas: Execution of ["terraform" "providers" "schema" "-json"] canceled.
signal: killed

@paultyng paultyng added the enhancement New feature or request label Jun 4, 2020
@smiller171
Copy link
Author

Yes, we plan to add an initialization workflow where the extension prompts. We can use this as the tracking issue (I'm still working my way through issue cleanup and creation).

This isn't just a matter of there not being a built-in workflow. It's totally impossible to resolve this. It instructs me to run terraform init but it's definitely initialized and not working I've tried running init several times to no avail.

@paultyng
Copy link
Contributor

paultyng commented Jun 4, 2020

@forstermatth unfortunately multi-folder is not yet supported by the LS. There is a possibility of doing multiple LS's per folder, or supporting multiple folders in a single LS process, and I don't know that we have chosen a direction yet, you can track that in #330

@paultyng
Copy link
Contributor

paultyng commented Jun 4, 2020

@smiller171 what Terraform version are you on? (we should really output that in the logs probably cc @radeksimko)

Update I should work on my log reading skills, disregard the output comment!

@smiller171
Copy link
Author

smiller171 commented Jun 4, 2020

well, guess it'll be a while before the new language server is even remotely ready for me then. re:multi-folder support

unfortunately I can't even get the workflow working for configuring a different language server so I can keep using the old one.

@paultyng The run in the logs here was 0.12.26. I use tfenv and have tried several different versions at this point.

@smiller171
Copy link
Author

@muram that'd be because this new version isn't published yet, you need to sideload it.

Also your comment is totally irrelevant to this issue.

@paultyng
Copy link
Contributor

paultyng commented Jun 4, 2020

@muram you'll need to manually download and install it from the GitHub releases page. It won't hit the marketplace until next week or the week after most likely.

@muram
Copy link

muram commented Jun 4, 2020

Got it, thank you @smiller171 @paultyng and sorry for hijacking this thread

BTW, now I've the same exact issue reported by @sgmiller , so I'm in the right place now 😄

@matt-forster
Copy link

matt-forster commented Jun 4, 2020

@paultyng

@smiller171 what Terraform version are you on? (we should really output that in the logs probably cc @radeksimko )

The version is output in the logs, from @smiller171's output;

2020/06/04 15:37:54 initialize.go:90: Found compatible Terraform version (0.12.26) at /usr/local/bin/terraform

@paultyng
Copy link
Contributor

paultyng commented Jun 4, 2020

@smiller171 I really appreciate you trying this and providing feedback and understand if its possibly too rough/early for you.

One more data collection thing, can you manually run the command referenced in that output log: terraform providers schema -json.

My guess is this is tfenv related, I don't have that setup locally, but I'll spin up an environment to test it shortly.

@paultyng
Copy link
Contributor

paultyng commented Jun 4, 2020

You can manually override how terraform is invoked in the LS in settings by modifying the args array. It should start with the serve command but then can use the following flags:

Usage: terraform-ls serve [options]

Starts the Language Server

Options:

  -log-file string
        path to a file to log into with support for variables (e.g. Timestamp, Pid, Ppid) via Go template syntax {{.VarName}}
  -port int
        port number to listen on (turns server into TCP mode)
  -tf-exec string
        path to Terraform binary
  -tf-exec-timeout string
        Overrides Terraform execution timeout (e.g. 30s)
  -tf-log-file string
        path to a file for Terraform executions to be logged into with support for variables (e.g. Timestamp, Pid, Ppid) via Go template syntax {{.VarName}}
"terraform.languageServer": {
        "external": true,
        "args": [
            "serve",
            "-tf-exec=/home/paul/go/bin/terraform",
        ]
    },

@smiller171
Copy link
Author

@paultyng

default ❯ terraform providers schema -json
{"format_version":"0.1"}

This is in a pretty small module.

@radeksimko
Copy link
Member

Just to provide some explanation/background, this error

Workspace not initialized. Please run terraform init

would be returned when this path doesn't exist:

filepath.Join(dir, ".terraform",
	"plugins",
	runtime.GOOS+"_"+runtime.GOARCH,
	"lock.json")

where dir is the current working directory, e.g. ./.terraform/plugins/darwin_amd64/lock.json on macOS.

This is the default path to the plugin cache lock file; an implementation detail of how Terraform keeps track of providers locally after they are downloaded via terraform init.

This is admittedly a very simplified way of detecting whether a workspace was initialized and as such is has some known flaws:

All of the above cases are valid use cases we want to support, just bear in mind that this is an initial release, so we did take some shortcuts (including not supporting the above yet) to gather early feedback and better gauge the priorities based on it.

With that in mind - does any of the above describe your situation? If not - can you please check if the lock file exists in the root of the directory you are opening in VSCode under .terraform? Also do you mind sharing any more details about where and how you init your folder? e.g. do you use any Terraform wrapper? Does it pass any particular flags or environment variables down to Terraform?

Thank you all for sharing this early feedback!

@marksmall
Copy link

I made some comments in #275 and was asked to look here for one of the problems I came up against. I think this explains why code thought the workspace wasn't initialised. The project I used is not a terraform project as such, but an application, which uses terraform to manage the deployment. So, our terraform code is not at the top-level, rather

PROJ_ROOT/
    terraform/
        deploy/
            *.tf

This explains the problem I was seeing.

@radeksimko
Copy link
Member

@marksmall Understood, that is a valid use case we intend to support. Have you tried opening the deploy folder directly as a project? I'm not saying that should be a long-term solution, but a workaround?

Relatedly am I right to say that you would normally run terraform init inside the deploy folder?

@marksmall
Copy link

@radeksimko That is probably what I'll end up doing as a workaround while this problem is being fixed. It's not a big deal for me in the grand scheme of things.

As to you your question on terraform init, you are correct, I would run that in the deploy folder.

@smiller171
Copy link
Author

smiller171 commented Jun 5, 2020

@radeksimko I don't think any of these describe my situation. Is it possible that lock file is not created if no plugins are in use?

The lock file does not exist for me, and I have run terraform init

@radeksimko
Copy link
Member

radeksimko commented Jun 5, 2020

@smiller171

Is it possible that lock file is not created if no plugins are in use?

Yes, that is certainly possible. terraform init won't create any plugin cache if there aren't any plugins defined in the config.

I suppose that use case would be described as "I'm starting from scratch and don't have any code yet"? Which is also a totally valid (and common) use case we want to support. One way we can support that is by not erroring when schema isn't available on initialization as per hashicorp/terraform-ls#83

@smiller171
Copy link
Author

I suppose that use case would be described as "I'm starting from scratch and don't have any code yet"? Which is also a totally valid (and common) use case we want to support. One way we can support that is by not erroring when schema isn't available on initialization as per hashicorp/terraform-ls#83

I think there's only one plugin we ever use, and it's an in-house plugin that we'll be deprecating once custom validation is in a good place. We have more than 70 terraform repos and I think that's the only plugin we use in any of them.

@radeksimko
Copy link
Member

@smiller171 If there is one plugin then there should be a plugin cache and therefore a lock file.

Can you share some details about how/where you run terraform init then? Do you use any wrapper like Terragrunt, or do you pass any particular flags or ENV variables to terraform init? Can you check ls -la output after terraform init? Is there .terraform folder at all?

I think there's only one plugin we ever use, and it's an in-house plugin that we'll be deprecating once custom validation is in a good place.

I'm having trouble understanding how could you use Terraform without any plugin - it doesn't seem very useful on its own? So just to clarify - when I say plugin I mean a provider (like any provider from https://github.com/terraform-providers/). Are we on the same page? 😅

@smiller171
Copy link
Author

@radeksimko ok, I didn't realize that providers show up as plugins. This is still an issue for nearly all of our modules because it only creates the .terraform/plugins dir if you explicitly call the provider, not if you're expecting the provider to be implicitly passed by the parent.

When I explicitly call the provider and init the directory and lockfile are created, but this isn't ideal within a child module.

In all cases it is recommended to keep explicit provider configurations only in the root module and pass them (whether implicitly or explicitly) down to descendent modules. This avoids the provider configurations from being "lost" when descendent modules are removed from the configuration. It also allows the user of a configuration to determine which providers require credentials by inspecting only the root module.

@smiller171
Copy link
Author

ok, I've just realized that the plugins lock is also created if I add the providers I'm using to required_providers (which is best practice and I just hadn't here) This at least unblocks me but since Terraform doesn't enforce this it creates problems for the functionality of the language server.

@dimisjim
Copy link

Hashicorp took the initiative to work on this project. Of course they need to think this through.

@J0F3
Copy link

J0F3 commented Jun 11, 2020

@smiller171
Hmm, I don't think so. It works for other extensions but not for this one because simply no older version are found/published in the marketplace.
#372 describes it. At least we can now manually download the old version...

@smiller171
Copy link
Author

oh...that's not good...

@benmontour-wf
Copy link

I have things structured in the Terragrunt style, with an infrastructure-live repo that contains only terragrunt.hcl files that reference modules, and a modules repo that contains said Terraform modules. I used to use this extension to keep those modules and hcl files properly formatted and linted. I don't ever run Terraform commands from my local Terraform folders. I have automation that pulls down repos and runs commands as part of it's build/deploy. This extension has basically become useless for me now, since I don't have the root modules folder init'd.

@mgreen-sm
Copy link

@radeksimko:

This would be our use case. We use our own variant of tfutils/tfscaffold, which does indeed set the TF_PLUGIN_CACHE_DIR to something other than ./terraform by default (due to it cd-ing into a component directory).

So it would be good to see the option to provide the option to specify the directory, rather than just auto-detect it.

@nfeltrin7s
Copy link

My use case is within:

I tried disabling the language server as a workaround, but it still produces the error message at startup. Is that expected? Is there any other way to disable the LS other than by using the command in the interface (configuration files etc)?

@paultyng
Copy link
Contributor

FYI, the downgrading issue is an upstream VS Code issue (see microsoft/vscode#99699 (comment)). We will track the upstream in #385 and provide updates there.

@mieseprem
Copy link

Hello folks,

yesterday I ran into this issue and found the reason in the way I work.
In VSCode my primary shell is WSL Shell. Outside of VS Code I always use Ubuntu WSL Shell.
If I initialize my terraform project plugins are stored in .terraform/plugins/linux_amd64/
On VS Code startup terraform-ls is executed as windows executable. It doesn't take the linux_amd64 directory into account.
My workaround was to initialize the project a seccond time out of a windows console with a terraform windows binary. After that a second folder unter plugins/ was created (.terraform/plugins/windows_amd64). Now startup of terraform-ls in VS Code don't crash anymore.

@nhart-alf
Copy link

nhart-alf commented Jun 18, 2020

Hello folks,

yesterday I ran into this issue and found the reason in the way I work.
In VSCode my primary shell is WSL Shell. Outside of VS Code I always use Ubuntu WSL Shell.
If I initialize my terraform project plugins are stored in .terraform/plugins/linux_amd64/
On VS Code startup terraform-ls is executed as windows executable. It doesn't take the linux_amd64 directory into account.
My workaround was to initialize the project a seccond time out of a windows console with a terraform windows binary. After that a second folder unter plugins/ was created (.terraform/plugins/windows_amd64). Now startup of terraform-ls in VS Code don't crash anymore.

This worked for me also, running WSL as my default terminal within VS Code.
We also use Terragrunt centrally, decoupling the cache from the TF files themselves. So I just created a barebones .tf file in my project directory to list the providers I need and ran init from Windows shell.

@J0F3
Copy link

J0F3 commented Jun 18, 2020

@mieseprem Btw. Also the Remote - WSL extension may help you a lot with this workflow. It allows basically to run the whole VS Code in the context of WSL and so you would not need to run a second init in Windows nor you need the Windows Terraform executable at all.
I can really recommend it, especially together with the Terraforming extension.

@tb102122
Copy link

I found a simple workaround that works well for me. I added a single terraform-ls.tf file at the root of the project with only a list of providers I use.

UPDATE: you need to run terraform init from the root of your project (the server won't do it for you)

quick and simple workaround! Thanks for the hint.

@WodansSon
Copy link

WodansSon commented Jun 19, 2020

I too hit this issue, the way I worked around it was to copy a random configuration from the examples folder into the root of my github repro forked directory, opened a windows command prompt to that folder and ran the terraform init command. Once it was initialized I simply deleted the files I copied over. Once I opened VSCode again the issue was fixed. Looks like it just needed to bin place the new runtime for VSCode to pick up the new bits or something along those lines. Would be nice if the VSCode extension did this bit for you, but a pretty simple workaround. HTH 🙂

@moosahmed
Copy link

The workaround I used and it works.

I copied a .terraform dir that has the plugins/darwin_amd64/lock.json from a subdirectory that had it and pasted it in the root directory I am opening in vscode.

This solved the issue. But is a horrible workaround.

@mislavcimpersak
Copy link

Reporting another horrible workaround:

made a symlink in the root dir of my project:

ln -s ./infrastructure/.terraform .terraform

My dir structure:

.
├── .git
├── .terraform -> ./infrastructure/.terraform
├── .vscode
│   └── settings.json
├── infrastructure
|   ├── .terraform
|   ├── main.tf
└── normal project stuff

@aaronsteers
Copy link
Contributor

Hi, Terraform. Can we please put a note in the Extension readme that explicitly states that multi-folder workspaces are not supported - along with any other caveats of expected and not supported folder structures? Would have saved me 2 hours today, probably hundreds (thousands?) of hours per month across all users.

Thank you!!

@aaronsteers
Copy link
Contributor

aaronsteers commented Jul 3, 2020

Fwiw, I still haven't gotten the features to work properly but it sounds like that's because in addition to using multi-folder workspaces exclusively, I'm also using non-traditional folder structures. 🤦‍♂️

I'm strategically deciding to just give up for now and live without the autocomplete and syntax-highlighting goodness, but will watch this thread for resolution. Please someone post these caveats to the readme of the extension. 🙏

UPDATE: I'm feeling empowered now. Apparently it's all in the repo and I can just create a PR. :) #430 is ready for review.

aaronsteers pushed a commit to aaronsteers/vscode-terraform that referenced this issue Jul 3, 2020
@aaronsteers
Copy link
Contributor

Hi, Terraform. Can we please put a note in the Extension readme that explicitly states that multi-folder workspaces are not supported - along with any other caveats of expected and not supported folder structures? Would have saved me 2 hours today, probably hundreds (thousands?) of hours per month across all users.

Thank you!!

Proposal for review: #430

paultyng pushed a commit that referenced this issue Jul 7, 2020
@taylorsmcclure
Copy link

I really hope this gets merged. I have a workspace with a ton of separate terraform repos in various different paths on my local machine, and I have to do the "shuffle the directory to the top" dance to get it to work properly.

@radeksimko
Copy link
Member

Hi folks,
the issue is not addressed yet, but we have a plan for addressing it and I'm just converging all the issues with the same root cause, such as this one, into a single issue: #569

Thank you for understanding and patience.

@ghost
Copy link

ghost commented Mar 27, 2021

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 as resolved and limited conversation to collaborators Mar 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests