Closed novekm closed 1 week ago
Hi @novekm!
Sorry, the VS Code extension and language server don't support Terraform test files today. We are tracking this work in #1534.
By default, the extension ignores *.tftest.hcl
files and doesn't send them to the language server, which seems to be the case here. This usually happens because you have manually assigned the Terraform language ID to the test files.
You can check (and change) the language ID in the bottom right corner. It should be HCL
for *.tftest.hcl
files. To get syntax highlighting for HCL files, you can install the vscode-hcl extension.
Hope this helps! Let me know if it solves your problem.
Thanks @dbanck! I've downloaded the extension you mentioned and have now manually changed the language ID to HCL
for the test files, however still getting the following error: Unexpected block: Blocks of type "run" are not expected here Terraform
. It seems to still be trying to use the Terraform extension in stead of the vscode-hcl extension, even though I've manually set HCL
for language ID. Is there anything else I need to do?
Can you please check if your VS Code configuration contains any manual file associations?
{
"files.associations": {
...
}
}
Hi @dbanck, it looks like this one is set:
"files.associations": {
"*.hcl": "terraform"
},
I don't recall setting this manually. Should this be removed?
Yes! This can be removed and should solve your issue
Thanks! I commented out those lines and it looks like the syntax validation errors are gone. I'll keep tracking #1534 to see when this is eventually added to Terraform. Thanks again!
That's great to hear!
Closing this for now. Feel free to open a new issue if something else comes up.
Extension Version
v2.30.2
VS Code Version
Version: 1.90.0 (Universal) Commit: 89de5a8d4d6205e5b11647eb6a74844ca23d2573 Date: 2024-06-04T19:34:44.157Z Electron: 29.4.0 ElectronBuildId: 9593362 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Darwin arm64 23.5.0
Operating System
macOS Sonoma Version 14.5
Terraform Version
Terraform v1.8.2
Steps to Reproduce
*.tftest.hcl
run
blockExpected Behavior
Syntax validation works properly
Actual Behavior
Receive validation error "Blocks of type "run" are not expected here. which is incorrect, as run blocks should be included in test files. So far I've been just ignoring it since it's an incorrect error, but it's a bit annoying and can make troubleshooting more difficult. This issue has persisted for multiple Terraform versions and multiple macOS versions in my testing.
What's odd is that if you quit and re-open VSCode, there is no error until you make any changes in files. Then the incorrect errors appear again. Only way to temporarily resolve is to quit and re-open VSCode, but the issue will continue to reappear.
Terraform Configuration
Project Structure
Gist
No response
Anything Else?
No response
Workarounds
If you quit and re-open VSCode, there is no error until you make any changes in files. Then the incorrect errors appear again. Only way to temporarily resolve is to quit and re-open VSCode, but the issue will continue to reappear.
References
No response
Help Wanted
Community Note