Terraform version: v0.13.3
VSCode Plugin version: v2.2.3
Terraform-ls: v0.7.0
Tested on Mac OS and Windows 10 with WSL2 (Ubuntu 20.04) - both have the same issues
Problem
I don't have any auto completion - even for the most basic Terraform code.
The Terraform VSCode plugin has always caused problems for me since v2.0.0. I'm really tired of fighting with these issues but at the same time I prefer VSCode over IntelliJ (where Terraform is supported perfectly without any issues though). So this is another try to address these issues. Looking at these issues and speaking to colleagues I know this is not just me.
Reproducing this issue
I can't tell whether you can reproduce this, but I'd like to share what exactly I did.
terraform {
required_version = ">=0.13.3, <0.14"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 3.41, <4.0.0"
}
}
}
locals {
labels = {
foo = "bar"
}
}
resource "google_project" "this" {
name = "bla"
project_id = "bla"
labels = local.labels
auto_create_network = false
skip_delete = true
}
terraform init - just like the warning at the bottom right side indicates (it requires that)local.labels at the end, hoping for auto completion. But just the vscode word check pops up: 
Additional context:
Every time I trigger an autocomplete request (e.g. using ctrl + space in that line), the following log is printed in the terraform-ls:
2020/10/03 23:44:05 server.go:568: Received 1 new requests
2020/10/03 23:44:05 server.go:174: Processing 1 requests
2020/10/03 23:44:05 server.go:265: Checking request for "textDocument/completion": {"textDocument":{"uri":"file:///home/h9pe/terraform-vscode-debug/main.tf"},"position":{"line":21,"character":34},"context":{"triggerKind":1}}
2020/10/03 23:44:05 rpc_logger.go:29: Incoming request for "textDocument/completion" (ID 78): {"textDocument":{"uri":"file:///home/h9pe/terraform-vscode-debug/main.tf"},"position":{"line":21,"character":34},"context":{"triggerKind":1}}
2020/10/03 23:44:05 complete.go:31: Finding block at position lsp.TextDocumentPositionParams{TextDocument:lsp.TextDocumentIdentifier{URI:"file:///home/h9pe/terraform-vscode-debug/main.tf"}, Position:lsp.Position{Line:21, Character:34}}
2020/10/03 23:44:05 rpc_logger.go:45: Error for "textDocument/completion" (ID 78): [-32098] root module not found for /home/h9pe/terraform-vscode-debug
2020/10/03 23:44:05 server.go:246: Completed 1 requests [158.8µs elapsed]
[Error - 11:44:05 PM] Request textDocument/completion failed.
Message: root module not found for /home/h9pe/terraform-vscode-debug
Code: -32098
Other times (such as after reloading the VSCode window) I get the following logs printed - but I still don't get any autocomplete suggestions then even though "local.labels" should be suggested:
2020/10/03 23:54:47 server.go:265: Checking request for "textDocument/completion": {"textDocument":{"uri":"file:///home/h9pe/terraform-vscode-debug/main.tf"},"position":{"line":21,"character":34},"context":{"triggerKind":1}}
2020/10/03 23:54:47 rpc_logger.go:29: Incoming request for "textDocument/completion" (ID 3): {"textDocument":{"uri":"file:///home/h9pe/terraform-vscode-debug/main.tf"},"position":{"line":21,"character":34},"context":{"triggerKind":1}}
2020/10/03 23:54:47 complete.go:31: Finding block at position lsp.TextDocumentPositionParams{TextDocument:lsp.TextDocumentIdentifier{URI:"file:///home/h9pe/terraform-vscode-debug/main.tf"}, Position:lsp.Position{Line:21, Character:34}}
2020/10/03 23:54:47 root_module_manager.go:149: direct root module lookup succeeded: /home/h9pe/terraform-vscode-debug
2020/10/03 23:54:47 root_module_manager.go:149: direct root module lookup succeeded: /home/h9pe/terraform-vscode-debug
2020/10/03 23:54:47 root_module_manager.go:149: direct root module lookup succeeded: /home/h9pe/terraform-vscode-debug
2020/10/03 23:54:47 parser.go:234: Parsed block type: "resource"
2020/10/03 23:54:47 schema_storage.go:196: Reading "google_project" resource schema
2020/10/03 23:54:47 schema_storage.go:135: Acquiring semaphore before reading schema
2020/10/03 23:54:47 config_block.go:103: avoiding RHS completion as it's not yet implemented
2020/10/03 23:54:47 rpc_logger.go:50: Response to "textDocument/completion" (ID 3): {"isIncomplete":false,"items":null}
2020/10/03 23:54:47 server.go:246: Completed 1 requests [439.9µs elapsed]
terraform-ls issue or not!?
Even though this looks like an issue in the terraform-ls the maintainer over there say this issue is a vscode-terraform issue. Can we end this ping-pong somehow? https://github.com/hashicorp/terraform-ls/issues/221#issuecomment-665045347 .
Please let me know if I can provide additional input.
I also have this issue
I once remember a "rescan/reparse" style option, but that could have been from the 3rd party plugin, as I can no longer find it.
I've tried running init -upgrade and restarting, just on hopes, but I can't seem to kickstart it, either.
Different versions here:
windows 7 + remote SSH on RHEL 7.3 (which is where the TF binary is)
terraform v0.12.20
vscode 1.50.1
I'm getting this error but its inconsistent. E.g I write 'data' and it autocompletes
data "" "name" {
}
But then when i write 'statement' within that block or 'actions' within the statement block it has stopped working, this was working last night within the same workspace so no idea why it stopped.
i have this Issue as well. Particularly annoying to me is that intellijs terraform plugin seems to be much better, it even suggests autocompletion of the resources you drew up. so if you have say an aws_security_group called foobar, so if you write:
aws_se .... autocompete to aws_security_group. ..... and here you get recommended the sgs you have provisioned. which doesn't work at all with this plugin.
Is there something we need to do, or can provide, to get any input on this? I'd dive into it myself, but I honestly don't have the first clue on how to start or what's involved.
So I have installed this on my MAC and I am cannot get any code completion from terraform-ls or at least I don't think it is coming from it. I have enabled the logs and I see the terraform-ls server is running and collecting provider data but I don't think anything is loaded into it.
terraform-ls version 0.9.0
terraform version v0.13.5 + aws provider v3.15.0
vscode version 1.51.1
UPDATE: So I went into the setting.json and enabled trace.server: on and now I see code completion.
This is my settings.json
"terraform.languageServer": {
"args": [
"serve",
"-tf-exec=/usr/local/bin/terraform",
"-log-file=/local/terraform/terrarform-ls.log",
"-tf-log-file=/local/terraform/tf-ls-log.log"
],
"maxNumberOfProblems": 100,
"trace.server": "on"
}
thanks for the find!
I'll give that a shot.
Doesn't work on my end - I've tried setting the trace.server setting to _on_ as well, with no luck.
The only thing that works is syntax highlighting, and even that is a bit sketchy currently, locals with maps seem to break it a bit :(
Same issue. Is there any workaround for remote vscode servers?
I'm having the same problem—no autocompletion suggestions whatsoever. I've tried some of the proposed settings fixes found above and elsewhere, but to no avail. Would really appreciate a resolution!
terraform v0.14.6 (via Homebrew)
aws provider 2.70.0
terraform-ls 0.13.0/0.0.0-dev (via Homebrew)
VS Code 1.53.2
vscode-terraform 2.6.0
macOS 10.15.7
So I have installed this on my MAC and I am cannot get any code completion from terraform-ls or at least I don't think it is coming from it. I have enabled the logs and I see the terraform-ls server is running and collecting provider data but I don't think anything is loaded into it.
terraform-ls version 0.9.0
terraform version v0.13.5 + aws provider v3.15.0
vscode version 1.51.1UPDATE: So I went into the setting.json and enabled trace.server: on and now I see code completion.
This is my settings.json
"terraform.languageServer": { "args": [ "serve", "-tf-exec=/usr/local/bin/terraform", "-log-file=/local/terraform/terrarform-ls.log", "-tf-log-file=/local/terraform/tf-ls-log.log" ], "maxNumberOfProblems": 100, "trace.server": "on" }
Note that it should be "trace.server": "verbose", as "on" threw an error for me. Otherwise this worked for me as well. I did try first without the -tf-exec, but it was still throwing errors. I'm not sure where it finds terraform, since it's in my bash shell, vscode might not know where to find it. Once I added the path to terraform(the exe) via the -tf-exec things worked. I then was able to comment out the logging
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: https://github.com/hashicorp/vscode-terraform/issues/569
Thank you for understanding and patience.
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.
Most helpful comment
I also have this issue