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

Syntax validation throwing incorrect errors for Terraform Test files (*.tftest.hcl) #1783

Closed
1 task
novekm opened this issue Jun 24, 2024 · 8 comments
Closed
1 task
Labels
bug Something isn't working

Comments

@novekm
Copy link

novekm commented Jun 24, 2024

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

  1. Create file ending in *.tftest.hcl
  2. Create a run block
  3. 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

Expected 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

run "mandatory_plan_basic" {
  command = plan
  module {
    source = "../examples/create-users-and-groups"
  }
}

run "mandatory_apply_basic" {
  command = apply
  module {
    source = "./examples/basic"
  }
}

Project Structure

├── CODEOWNERS
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── NOTICE.txt
├── README.md
├── VERSION
├── data.tf
├── examples
│   ├── basic
│   ├── create-users-and-groups
│   ├── existing-users-and-groups
│   ├── google-workspace
│   └── inline-policy
├── locals.tf
├── main.tf
├── outputs.tf
├── providers.tf
├── test
│   ├── go.mod
│   ├── go.sum
│   └── main_test.go
├── tests
│   └── 01_mandatory.tftest.hcl
├── tf.json
├── tf.plan
└── variables.tf

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

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@novekm novekm added the bug Something isn't working label Jun 24, 2024
@dbanck
Copy link
Member

dbanck commented Jun 24, 2024

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.

@novekm
Copy link
Author

novekm commented Jun 24, 2024

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?

@dbanck
Copy link
Member

dbanck commented Jun 25, 2024

Can you please check if your VS Code configuration contains any manual file associations?

{
  "files.associations": {
    ...
  }
}

@novekm
Copy link
Author

novekm commented Jun 26, 2024

Hi @dbanck, it looks like this one is set:

  "files.associations": {
    "*.hcl": "terraform"
  },

I don't recall setting this manually. Should this be removed?

@dbanck
Copy link
Member

dbanck commented Jun 26, 2024

Yes! This can be removed and should solve your issue

@novekm
Copy link
Author

novekm commented Jun 26, 2024

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!

@dbanck
Copy link
Member

dbanck commented Jun 27, 2024

That's great to hear!

Closing this for now. Feel free to open a new issue if something else comes up.

@dbanck dbanck closed this as completed Jun 27, 2024
Copy link

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants