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 in sub-directories of root configuration reporting as incorrect syntax #1628

Closed
1 task
pro-krastinator opened this issue Nov 15, 2023 · 4 comments
Labels

Comments

@pro-krastinator
Copy link

pro-krastinator commented Nov 15, 2023

Extension Version

v2.29.0

VS Code Version

Version: 1.84.2 (user setup)
Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
Date: 2023-11-09T10:51:52.184Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19045

Operating System

Edition: Windows 10 Enterprise, Version: 22H2, Build: 19045.3570

Terraform Version

Terraform v1.5.7 on linux_amd64

Steps to Reproduce

The issue is similar to the closed #1574

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

valid tfvars file reporting as having incorrect syntax;

Screenshot 2023-11-15 170826

Expected Behavior

Valid HCL tfvars aren't highlighted.

Actual Behavior

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

Terraform Configuration

variable "test" {
    type = string
}

output "test" {
  value       = var.test
}

file nonprod/terraform.tfvars

test = "any_text"

Project Structure

.
├── nonprod
│   └── terraform.tfvars
├── output.tf
└── prod
    └── terrafrom.tfvars

2 directories, 3 files

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

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
@pro-krastinator pro-krastinator added the bug Something isn't working label Nov 15, 2023
@radeksimko
Copy link
Member

Hi @pro-krastinator
This looks pretty much exactly like a bug we already fixed in #1574 as you noted.

Can you check the bottom bar for some more details? Specifically:

  1. version of the language server running
  2. language ID chosen/detected for the file

Screenshot 2023-11-16 at 10 32 55

Ideally it should match what you see above, assuming this is on terraform.tfvars.

On a related note, can you double check for any custom terraform.* settings and ensure that for example you didn't specify custom path to the LS (via terraform.languageServer.path) or didn't instruct VS Code to treat *.tfvars files as terraform language (rather than terraform-vars?

@radeksimko radeksimko added question waiting-response and removed bug Something isn't working labels Nov 16, 2023
@pro-krastinator
Copy link
Author

Hi @pro-krastinator This looks pretty much exactly like a bug we already fixed in #1574 as you noted.

Can you check the bottom bar for some more details? Specifically:

1. version of the language server running

2. language ID chosen/detected for the file

Screenshot 2023-11-16 at 10 32 55

Ideally it should match what you see above, assuming this is on terraform.tfvars.

On a related note, can you double check for any custom terraform.* settings and ensure that for example you didn't specify custom path to the LS (via terraform.languageServer.path) or didn't instruct VS Code to treat *.tfvars files as terraform language (rather than terraform-vars?

Yes @radeksimko , you are right, most probably the cause was the line in my settings:

Screenshot 2023-11-17 125510

version of the language server running and language ID chosen/detected for the file:
Screenshot 2023-11-17 124739

I've forgot I've put it there having older version of vscode-terraform in order to avoid the reporting about incorrect syntax. That time it did the trick though... After updating to 2.29.0 it started to report tfvars again.
Once I removed the line from settings.json, the issue gone. Now the corresponding part looks like this:

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

I guess, this issue can be closed if you do not need to add anything in regards, just for other community members who might be searching about the same issue.
Thank you for the hint with file associations! 😄

@radeksimko
Copy link
Member

radeksimko commented Nov 17, 2023

I would still suggest you avoid any manual associations of any files (including *.tftpl) with terraform or terraform-vars.

The reason is that AFAICT in VS Code there's no way to tell what exact features you expect to receive for those file types and so what it will attempt to do is to provide all features that go far beyond just highlighting. That includes completion, hover, go-to-definition, diagnostics etc. - and pretty much everything other than syntax highlighting will not be relevant and can even be wrong - just like what you saw with *.tfvars. The simple way of putting it is that there is no resource blocks or data blocks and other language constructs in *.tfvars nor in *.tftpl and the extension will assume there may be if you tell it to treat it as terraform.

Until we build the support for template files (#636) the best solution is:

  1. Install the HCL extension
  2. Associate template files with hcl language
    "files.associations": {
        "*.tftpl": "hcl"
    }

That HCL extension does not make any assumptions about block or attribute names (unlike the Terraform one) and only provides basic syntax highlighting, which is probably the main feature you're looking for right now anyway.

@radeksimko radeksimko closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
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 Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants