vscode-terraform
vscode-terraform copied to clipboard
Document Terraform (CLI) as a dependency
I've also filed this as a bug for the terraform-ls repo: https://github.com/hashicorp/terraform-ls/issues/398
OS: Darwin x64 20.2.0 (macOS Big Sur Version 11.1) VS Code: 1.53.0 VS Code Terraform Extension: v2.5.0
The VS Code Terraform extension always gives me the following message whenever I open any .tf
file.
Then although I have already run terraform init
, when I click the terraform init button I get the following message.
I was able to replicate this error when opening VS Code into a folder with a single minimal main.tf
file.
File Tree
$ find . -print
.
./main.tf
./.terraform
./.terraform/plugins
./.terraform/plugins/darwin_amd64
./.terraform/plugins/darwin_amd64/terraform-provider-aws_v3.27.0_x5
./.terraform/plugins/darwin_amd64/lock.json
main.tf
terraform {
required_version = ">= 0.12.26"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
terraform version
output
$ terraform version
Terraform v0.12.30
+ provider.aws v3.27.0
terraform init
output
$ terraform init
Initializing the backend...
Initializing provider plugins...
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
terraform-ls logs output for the terraform VSCode extension. For this output:
- I opened VSCode to my test folder
- I opened
main.tf
which gave me the message in the first screenshot - I clicked the
terraform init
button in the popup message
Launching language server: /Users/aburck/.vscode/extensions/hashicorp.terraform-2.5.0/lsp/terraform-ls serve for folder: file:///Users/aburck/code/local/test/
2021/02/07 02:15:06 serve_command.go:137: Starting terraform-ls 0.13.0
2021/02/07 02:15:06 service.go:71: Preparing new session ...
2021/02/07 02:15:06 watcher.go:215: watching for changes ...
2021/02/07 02:15:06 langserver.go:69: Starting server (pid 81470) ...
2021/02/07 02:15:06 server.go:573: Received 1 new requests
2021/02/07 02:15:06 server.go:174: Processing 1 requests
2021/02/07 02:15:06 server.go:265: Checking request for "initialize": {"processId":81445,"clientInfo":{"name":"vscode","version":"1.53.0"},"rootPath":"/Users/aburck/code/local/test","rootUri":"file:///Users/aburck/code/local/test","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]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":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,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]}},"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},"activeParameterSupport":true},"contextSupport":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,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"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,"prepareSupportDefaultBehavior":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":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},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","member","macro","keyword","modifier","comment","string","number","regexp","operator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}}}},"window":{"workDoneProgress":true}},"initializationOptions":{"commandPrefix":"6","experimentalFeatures":{}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/aburck/code/local/test","name":"test"}]}
2021/02/07 02:15:06 rpc_logger.go:29: Incoming request for "initialize" (ID 0): {"processId":81445,"clientInfo":{"name":"vscode","version":"1.53.0"},"rootPath":"/Users/aburck/code/local/test","rootUri":"file:///Users/aburck/code/local/test","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]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true,"semanticTokens":{"refreshSupport":true}},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]},"codeDescriptionSupport":true,"dataSupport":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,"tagSupport":{"valueSet":[1]},"insertReplaceSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]}},"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},"activeParameterSupport":true},"contextSupport":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,"tagSupport":{"valueSet":[1]},"labelSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"disabledSupport":true,"dataSupport":true,"resolveSupport":{"properties":["edit"]},"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,"prepareSupportDefaultBehavior":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":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},"selectionRange":{"dynamicRegistration":true},"callHierarchy":{"dynamicRegistration":true},"semanticTokens":{"dynamicRegistration":true,"tokenTypes":["namespace","type","class","enum","interface","struct","typeParameter","parameter","variable","property","enumMember","event","function","member","macro","keyword","modifier","comment","string","number","regexp","operator"],"tokenModifiers":["declaration","definition","readonly","static","deprecated","abstract","async","modification","documentation","defaultLibrary"],"formats":["relative"],"requests":{"range":true,"full":{"delta":true}}}},"window":{"workDoneProgress":true}},"initializationOptions":{"commandPrefix":"6","experimentalFeatures":{}},"trace":"off","workspaceFolders":[{"uri":"file:///Users/aburck/code/local/test","name":"test"}]}
2021/02/07 02:15:06 walker.go:102: asynchronously walking through /Users/aburck/code/local/test
2021/02/07 02:15:06 rpc_logger.go:50: Response to "initialize" (ID 0): {"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"save":{}},"completionProvider":{},"hoverProvider":true,"signatureHelpProvider":{},"documentSymbolProvider":true,"codeLensProvider":{},"documentLinkProvider":{},"documentFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":""},"executeCommandProvider":{"commands":["6.terraform-ls.rootmodules","6.terraform-ls.terraform.init","6.terraform-ls.terraform.validate"],"workDoneProgress":true},"semanticTokensProvider":{"legend":{"tokenTypes":["type","string","property"],"tokenModifiers":["deprecated","modification"]},"full":true},"workspace":{"workspaceFolders":{}}},"serverInfo":{"name":"terraform-ls","version":"0.13.0"}}
2021/02/07 02:15:06 walker.go:150: found module /Users/aburck/code/local/test
2021/02/07 02:15:06 server.go:246: Completed 1 requests [2.831693ms elapsed]
2021/02/07 02:15:06 module_manager.go:67: MM: adding new module: /Users/aburck/code/local/test
2021/02/07 02:15:06 module_loader.go:164: ML: enqueing "OpTypeGetTerraformVersion" module operation: /Users/aburck/code/local/test
2021/02/07 02:15:06 module_loader.go:164: ML: enqueing "OpTypeObtainSchema" module operation: /Users/aburck/code/local/test
2021/02/07 02:15:06 walker.go:202: walking of /Users/aburck/code/local/test finished
2021/02/07 02:15:06 walker.go:75: stopping walker
2021/02/07 02:15:06 walker.go:108: async walking through /Users/aburck/code/local/test finished
2021/02/07 02:15:06 module_loader.go:136: executing "OpTypeGetTerraformVersion" for /Users/aburck/code/local/test
2021/02/07 02:15:06 module_ops.go:83: getting executor failed: no exec path provided for terraform
2021/02/07 02:15:06 module_loader.go:144: finished "OpTypeGetTerraformVersion" for /Users/aburck/code/local/test
2021/02/07 02:15:06 module_loader.go:136: executing "OpTypeObtainSchema" for /Users/aburck/code/local/test
2021/02/07 02:15:06 module_ops.go:108: getting executor failed: no exec path provided for terraform
2021/02/07 02:15:06 module_loader.go:147: finished "OpTypeObtainSchema" for /Users/aburck/code/local/test
2021/02/07 02:15:06 server.go:573: Received 1 new requests
2021/02/07 02:15:06 server.go:174: Processing 1 requests
2021/02/07 02:15:06 server.go:265: Checking request for "initialized": {}
2021/02/07 02:15:06 rpc_logger.go:29: Incoming notification for "initialized": {}
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "textDocument/didOpen": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf","languageId":"terraform","version":1,"text":"terraform {\n required_version = \">= 0.12.26\"\n\n required_providers {\n aws = {\n source = \"hashicorp/aws\"\n version = \"~> 3.0\"\n }\n }\n}\n\nprovider \"aws\" {\n region = \"us-east-1\"\n}\n"}}
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 rpc_logger.go:29: Incoming notification for "textDocument/didOpen": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf","languageId":"terraform","version":1,"text":"terraform {\n required_version = \">= 0.12.26\"\n\n required_providers {\n aws = {\n source = \"hashicorp/aws\"\n version = \"~> 3.0\"\n }\n }\n}\n\nprovider \"aws\" {\n region = \"us-east-1\"\n}\n"}}
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "textDocument/documentLink": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 server.go:297: Task error: [-32601] no such method "textDocument/documentLink"
2021/02/07 02:15:32 did_open.go:58: opened module: /Users/aburck/code/local/test
2021/02/07 02:15:32 module_loader.go:164: ML: enqueing "OpTypeParseConfiguration" module operation: /Users/aburck/code/local/test
2021/02/07 02:15:32 module_loader.go:136: executing "OpTypeParseConfiguration" for /Users/aburck/code/local/test
2021/02/07 02:15:32 module_loader.go:150: finished "OpTypeParseConfiguration" for /Users/aburck/code/local/test
2021/02/07 02:15:32 watcher.go:73: adding module for watching: /Users/aburck/code/local/test
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "workspace/executeCommand": {"command":"6.terraform-ls.rootmodules","arguments":["uri=file:///Users/aburck/code/local/test/main.tf"]}
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "textDocument/documentSymbol": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 rpc_logger.go:29: Incoming request for "textDocument/documentSymbol" (ID 3): {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 rpc_logger.go:50: Response to "textDocument/documentSymbol" (ID 3): [{"name":"terraform","kind":5,"location":{"uri":"file:///Users/aburck/code/local/test/main.tf","range":{"start":{"line":0,"character":0},"end":{"line":9,"character":1}}}},{"name":"provider \"aws\"","kind":5,"location":{"uri":"file:///Users/aburck/code/local/test/main.tf","range":{"start":{"line":11,"character":0},"end":{"line":13,"character":1}}}}]
2021/02/07 02:15:32 server.go:246: Completed 1 requests [207.198µs elapsed]
2021/02/07 02:15:32 server.go:443: Posting server notification "textDocument/publishDiagnostics" {"uri":"file:///Users/aburck/code/local/test/main.tf","diagnostics":[]}
2021/02/07 02:15:32 server.go:443: Posting server call "window/showMessageRequest" {"type":3,"message":"No schema found for \"test\". Functionality may be limited. You may need to run terraform init.","actions":[{"title":"terraform init"}]}
2021/02/07 02:15:32 rpc_logger.go:45: Error for "textDocument/documentLink" (ID 1): [-32601] no such method "textDocument/documentLink"
2021/02/07 02:15:32 server.go:246: Completed 1 requests [3.41341ms elapsed]
2021/02/07 02:15:32 rpc_logger.go:29: Incoming request for "workspace/executeCommand" (ID 2): {"command":"6.terraform-ls.rootmodules","arguments":["uri=file:///Users/aburck/code/local/test/main.tf"]}
2021/02/07 02:15:32 rpc_logger.go:50: Response to "workspace/executeCommand" (ID 2): {"responseVersion":0,"doneLoading":true,"rootModules":[]}
2021/02/07 02:15:32 server.go:246: Completed 1 requests [592.448µs elapsed]
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "textDocument/semanticTokens/full": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 rpc_logger.go:29: Incoming request for "textDocument/semanticTokens/full" (ID 4): {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 module_manager.go:140: falling back to preloaded schema for /Users/aburck/code/local/test...
[Error - 2:15:32 AM] Request textDocument/documentLink failed.
Message: no such method "textDocument/documentLink"
Code: -32601
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "textDocument/documentSymbol": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "textDocument/codeLens": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 server.go:297: Task error: [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:32 rpc_logger.go:45: Error for "textDocument/codeLens" (ID 6): [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:32 server.go:246: Completed 1 requests [76.85µs elapsed]
[Error - 2:15:32 AM] Request textDocument/codeLens failed.
Message: no such method "textDocument/codeLens"
Code: -32601
2021/02/07 02:15:32 server.go:573: Received 1 new requests
2021/02/07 02:15:32 server.go:174: Processing 1 requests
2021/02/07 02:15:32 server.go:265: Checking request for "textDocument/codeLens": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:32 server.go:297: Task error: [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:32 rpc_logger.go:45: Error for "textDocument/codeLens" (ID 7): [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:32 server.go:246: Completed 1 requests [77.992µs elapsed]
[Error - 2:15:32 AM] Request textDocument/codeLens failed.
Message: no such method "textDocument/codeLens"
Code: -32601
2021/02/07 02:15:33 module_manager.go:149: preloaded provider schema (134 providers) set for /Users/aburck/code/local/test
2021/02/07 02:15:33 rpc_logger.go:50: Response to "textDocument/semanticTokens/full" (ID 4): {"data":[0,0,9,0,0,1,2,16,2,0,2,2,18,0,0,1,4,3,2,0,7,0,8,0,0,0,9,5,1,2,1,2,6,2,2]}
2021/02/07 02:15:33 server.go:246: Completed 1 requests [895.307323ms elapsed]
2021/02/07 02:15:33 rpc_logger.go:29: Incoming request for "textDocument/documentSymbol" (ID 5): {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:33 rpc_logger.go:50: Response to "textDocument/documentSymbol" (ID 5): [{"name":"terraform","kind":5,"location":{"uri":"file:///Users/aburck/code/local/test/main.tf","range":{"start":{"line":0,"character":0},"end":{"line":9,"character":1}}}},{"name":"provider \"aws\"","kind":5,"location":{"uri":"file:///Users/aburck/code/local/test/main.tf","range":{"start":{"line":11,"character":0},"end":{"line":13,"character":1}}}}]
2021/02/07 02:15:33 server.go:246: Completed 1 requests [808.004139ms elapsed]
2021/02/07 02:15:36 server.go:573: Received 1 new requests
2021/02/07 02:15:36 server.go:174: Processing 1 requests
2021/02/07 02:15:36 server.go:265: Checking request for "":
2021/02/07 02:15:36 server.go:443: Posting server call "window/workDoneProgress/create" {"token":"a824b024-691c-11eb-889c-acde48001122"}
2021/02/07 02:15:36 server.go:573: Received 1 new requests
2021/02/07 02:15:36 server.go:174: Processing 1 requests
2021/02/07 02:15:36 server.go:265: Checking request for "":
2021/02/07 02:15:36 server.go:443: Posting server notification "window/showMessage" {"type":1,"message":"Initialization failed: no exec path provided for terraform"}
2021/02/07 02:15:36 server.go:573: Received 1 new requests
2021/02/07 02:15:36 server.go:174: Processing 1 requests
2021/02/07 02:15:36 server.go:265: Checking request for "textDocument/codeLens": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:36 server.go:297: Task error: [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:36 rpc_logger.go:45: Error for "textDocument/codeLens" (ID 8): [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:36 server.go:246: Completed 1 requests [64.883µs elapsed]
[Error - 2:15:36 AM] Request textDocument/codeLens failed.
Message: no such method "textDocument/codeLens"
Code: -32601
2021/02/07 02:15:36 server.go:573: Received 1 new requests
2021/02/07 02:15:36 server.go:174: Processing 1 requests
2021/02/07 02:15:36 server.go:265: Checking request for "textDocument/codeLens": {"textDocument":{"uri":"file:///Users/aburck/code/local/test/main.tf"}}
2021/02/07 02:15:36 server.go:297: Task error: [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:36 rpc_logger.go:45: Error for "textDocument/codeLens" (ID 9): [-32601] no such method "textDocument/codeLens"
2021/02/07 02:15:36 server.go:246: Completed 1 requests [43.055µs elapsed]
[Error - 2:15:36 AM] Request textDocument/codeLens failed.
Message: no such method "textDocument/codeLens"
Code: -32601
Terraform Install
$ which terraform
/Users/aburck/.local/bin/terraform
$ echo $PATH
/Users/aburck/.local/bin:...
I simply downloaded and extracted the terraform executable to ~/.local/bin
. Then I added ~/.local/bin
to my PATH via my ~/.zshrc
using export PATH="$HOME/.local/bin:$PATH"
Hi @burck1
I wasn't able to reproduce this, but given that you're on macOS, I'm guessing this could be caused by $PATH
not being propagated down to VS Code in certain circumstances.
For example when you launch any app from the Finder, Dock or Spotlight, they do not automatically inherit your shell environment. See https://stackoverflow.com/questions/135688/setting-environment-variables-on-os-x for more.
Assuming you are confident that launchd knows about /Users/aburck/.local/bin
I'm tempted to ask the obvious question - have you tried restarting VS Code and/or rebooting? As per the above, launchd might get chance to reload ENV variables on reboot.
If that still doesn't work, I would suggest you to try installing Terraform under a path which is known to launchd:
launchctl getenv PATH
Personally I use Homebrew to manage most of the software on my macOS and HashiCorp also provides official tap you can use to install Terraform from: https://github.com/hashicorp/homebrew-tap
Homebrew installs binaries under /usr/local/bin
which AFAIK is listed in the default $PATH
of launchd, which mitigates this problem.
As for your other issue in the LS repository I will leave it open, because I think we could do better job in the error messaging there, perhaps even consider printing out the $PATH
.
Hi @radeksimko.
I added terraform
to my /usr/local/bin
directory and I now no longer get the error message and auto-complete is now working! Thank you for the help in finding a workaround.
In my scenario, since I am using zsh as my primary shell environment and added the ~/.local/bin
directory to my PATH via my ~/.zshrc
file, it must be that VS Code nor this extension loads my primary shell environment, but rather uses its own set of environment variables?
Note: Running launchctl getenv PATH
on my system gives me nothing.
$ launchctl getenv PATH
$ echo $?
0
Though adding terraform
to my /usr/local/bin
directory resolved my problem temporarily, I have a few comments:
- I may have missed it, but it wasn't clear to me from the docs that
terraform
is a dependency of this extension nor that it is required to be added to whatever PATH VS Code uses. It seems obvious now, but I had originally made an assumption that the this extension was a separate process that didn't use the terraform executable. - Having a requirement on a single global terraform install (like you mention via homebrew) isn't a great option for me and I suspect potentially other users. Reason being that terraform is used pretty broadly at my work and I often need to switch the version of terraform I'm using based on the repo I'm working on (often multiple times a day). It would be better if I had the ability to specify a path to my desired terraform executable within my VS Code workspace settings for this extension.
- Even better would be the ability to specify the terraform version per sub-folder in my repos as sometimes the repos I work with have multiple sub-folders that contain root terraform modules but use different terraform versions.
I may have missed it, but it wasn't clear to me from the docs that terraform is a dependency of this extension nor that it is required to be added to whatever PATH VS Code uses. It seems obvious now, but I had originally made an assumption that the this extension was a separate process that didn't use the terraform executable.
That is a good point. We should make that more obvious. Relatedly we have also discussed the option of prompting the user to install Terraform automatically via click of a button to a temp folder, similar to how the extension installs the language server.
Having a requirement on a single global terraform install (like you mention via homebrew) isn't a great option for me and I suspect potentially other users. Reason being that terraform is used pretty broadly at my work and I often need to switch the version of terraform I'm using based on the repo I'm working on (often multiple times a day). It would be better if I had the ability to specify a path to my desired terraform executable within my VS Code workspace settings for this extension.
This is already possible today via settings, see https://github.com/hashicorp/vscode-terraform/wiki/Manually-Setting-the-Terraform-Executable-Path
Even better would be the ability to specify the terraform version per sub-folder in my repos as sometimes the repos I work with have multiple sub-folders that contain root terraform modules but use different terraform versions.
I would be curious to know how you manage these different installations of Terraform locally. Would you just wget
the archive and unzip the binary somewhere to $PATH
? How do you know which version of Terraform to use when working with a particular project?
I imagine this is a common problem for someone who manages multiple projects and so understanding your workflow would help us support it better.
I'm aware some people use tfenv to deal with this problem and the language server should be able to pick it up automatically, although there are some currently known challenges with tfenv:
- https://github.com/tfutils/tfenv/issues/196
- https://github.com/hashicorp/terraform-ls/issues/305
- https://github.com/hashicorp/terraform-ls/issues/128
Can this error message be disabled completely? It didn't existed in a previous version (no idea which since it got auto updated)
I move between directories and TF versions and every time I open a file I get the annoying message
No schema found for...
I only want the syntax highlight and formatting help. How can I disable the rest?
I would be curious to know how you manage these different installations of Terraform locally. Would you just
wget
the archive and unzip the binary somewhere to$PATH
? How do you know which version of Terraform to use when working with a particular project?I imagine this is a common problem for someone who manages multiple projects and so understanding your workflow would help us support it better.
Not OP, but I can chime in. For switching terraform versions we've settled on Terraform Switcher. tfswitch swaps /usr/local/bin/terraform symlinks around instead of adding shims into the PATH.
Each of our workspaces and modules contain a .terraform-version file to facilitate switching to the correct terraform version. Looks like tfswitch also supports checking the versions.tf
directly for the terraform too.
I would be curious to know how you manage these different installations of Terraform locally. Would you just
wget
the archive and unzip the binary somewhere to$PATH
? How do you know which version of Terraform to use when working with a particular project?I imagine this is a common problem for someone who manages multiple projects and so understanding your workflow would help us support it better.
Sorry for the delayed response. We do something very similar to what @bevans-HD mentions. We commit a config file to our repos that specifies the terraform version to be used (among other CI / CD) settings. Then we've developed in-house wrapper around the terraform CLI that handles switching the terraform version used based on the config file (looks for the config file recursively in parent directories).
But for a more universal option, my suggestion for the vscode terraform extension would be to support the standard vscode extension workspace configuration settings that can be committed to our repos. Something along the lines of:
.vscode/settings.json
"terraform.version": "0.14.7"
Though it looks like we can override the terraform executable path, it'd be nice if the extension would handle downloading and switching it for us.
Furthermore, if this extension supported Multi-root Workspaces then we'd be able to setup each terraform configuration root in our repos with separate vscode settings and thus potentially separate terraform versions.
I would also like to add to this another tool version system called asdf which does add shims. Installing terraform from homebrew is honestly a very naive thing as there are very good use cases where you need multiple versions of Terraform as @burck1 mentioned.
When trying to override the path, however, it just crashes as it uses a shim and isn't a link to a binary.
@blairham This is very useful feedback.
I would also like to add to this another tool version system called asdf which does add shims.
The dependency on Terraform is largely a dependency of the language server itself, so from extension perspective a transitive one. There is currently some logic which does run Terraform CLI directly, but the overall aim is to keep such surface (direct communication between the extension and Terraform) minimal. Generally having one entry point is beneficial from all perspectives and that is the ultimate goal and also one of the reasons we maintain a language server.
Therefore if we are to somehow integrate with such tool and support it better it would be mostly on the language server side, or more specifically in terraform-exec
which is a library that the language server uses to discover and execute Terraform commands.
TL;DR The best place to track this feedback would be in https://github.com/hashicorp/terraform-exec/issues/6 or https://github.com/hashicorp/terraform-ls/issues/305
When trying to override the path, however, it just crashes as it uses a shim and isn't a link to a binary.
I believe this is related to the fact that the language server currently doesn't parse the flag value in any special way, as I also mentioned here: https://github.com/hashicorp/terraform-ls/issues/128#issuecomment-636789731
Unfortunately I haven't had much capacity available lately to improve https://github.com/mattn/go-shellwords/pull/39 in any way. If you are willing to jump in with some Powershell experience you are more than welcomed.
I'm getting a similar error:
Request textDocument/codeLens failed.
Message: no such method "textDocument/codeLens"
Code: -32601
And I do have Terraform installed and available on my $PATH, I'm using it, and even if I open the VSCode terminal and do a terraform --version
it works.
If I reload the VSCode window a few times the error stops to throw and the autoformatting works. 🤷
I'm going to re-open this until we document the optional dependency, probably under https://github.com/hashicorp/vscode-terraform#code-formatting
btw. you can also use tenv that support Terraform as well as OpenTofu (and Terragrunt :) ) in one tool. It allow you to simplify version management and can do much more, than tfswitch.