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

Valid tfvars found outside of root configuration reporting as incorrect syntax #1574

Closed
1 task
sheppyj opened this issue Oct 5, 2023 · 5 comments
Closed
1 task
Assignees
Labels
bug Something isn't working diagnostics

Comments

@sheppyj
Copy link

sheppyj commented Oct 5, 2023

Extension Version

2.28.0

VS Code Version

Version: 1.82.2 (Universal)
Commit: abd2f3db4bdb28f9e95536dfa84d8479f1eb312d
Date: 2023-09-14T05:59:47.790Z (3 wks ago)
Electron: 25.8.1
ElectronBuildId: 23779380
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 22.6.0

Operating System

macOS Ventura 13.6 (22G120)

Terraform Version

Terraform v1.4.6 on darwin_arm64

Steps to Reproduce

  1. Create simple Terraform configuration
  2. Create variables file environment/dev/terraform.tfvars

valid tfvars file reporting as having incorrect syntax;
image

Expected Behavior

Valid HCL tfvars aren't highlighted.

Actual Behavior

Error;
Unexpected attribute: An attribute named "test" is not expected here Terraform

Terraform Configuration

output.tf
variable "test" {
    type = string
}

output "test" {
  value       = var.test
}

environment/dev/terraform.tfvars
test = "hello"

Project Structure

.
├── environment
│   └── dev
│       └── terraform.tfvars
└── output.tf

Gist

No response

Anything Else?

No response

Workarounds

Dragging and dropping tfvars into root directory appear to work, syntax highlighting seems to behave as expected.

Reverting to previous version of extension 2.27.2

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
@radeksimko
Copy link
Member

This is helpful, thank you @sheppyj

It looks like we didn't give enough consideration to manually loaded *.tfvars files. Apologies for the confusion.

I think the best solution for now may be just excluding any non-autoloaded tfvars files from validation entirely as we cannot tell which module to they belong to.

I will look into implementing that patch.

@radeksimko
Copy link
Member

We actually already ignore non-autoloaded *.tfvars, which can be demonstrated below:

Screenshot 2023-10-05 at 17 50 11

Admittedly we still compute the diagnostics in this case but avoid publishing them. It's not a user-visible problem right now nonetheless.


What we do not account for however is a situation of a *.tfvars files with "autoloaded naming convention" (i.e. terraform.tfvars or *.auto.tfvars) in a random place which is not a module. That seems like a totally reasonable use case / naming, so we should account for it!

I have a patch which seems to be addressing the problem based on quick manual testing:

Screenshot 2023-10-05 at 17 56 20

I will post update when it gets merged & reaches a release.

@radeksimko
Copy link
Member

A new version 2.28.1 was just released. This fixes the reported bug. The update should appear automatically in VS Code.

Thank you for the timing and level of detail in your report @sheppyj


In case you experience any different validation related bug, please do let us know through a new issue.

@ufonalim
Copy link

@radeksimko I've same issue with *.tfvars' "Unexpected attribute" outside of module. plugin version is 2.28.2, what else I can check?

@radeksimko
Copy link
Member

@ufonalim Please file a new issue and attach more details, we'll be happy to look into it.

Just because the error message is the same does not always mean it's (a) the same bug, or (b) it is a bug at all.

Thanks!

@hashicorp hashicorp locked as off-topic and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants