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

Incorrect use of variables in terraform snippets #498

Open
echasnovski opened this issue Oct 3, 2024 · 2 comments
Open

Incorrect use of variables in terraform snippets #498

echasnovski opened this issue Oct 3, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@echasnovski
Copy link
Contributor

echasnovski commented Oct 3, 2024

Many snippets from 'terraform.json' do not follow the snippet grammar regarding variables (both upcoming 3.18 version and the current 3.17 version).

It states that variable name should match the following regex: [_a-zA-Z][_a-zA-Z0-9]*. The 'terraform.json' file contains a lot of instances that use period (.) and/or dash (-) inside variable name. Here are couple of example: one (${path.module}), two (${data.ibm_org.myResourceName-org.id}), three (${var.s3_bucket_name}). In total there are at least 90 instances of this currently (at 00ba9dd), some of them mixed with preceding \\ which makes the following $ be not recognized as variable at all (like here).

@OkelleyDevelopment OkelleyDevelopment added bug Something isn't working good first issue Good for newcomers labels Oct 7, 2024
@inarush0
Copy link

At first glance, it seems like the issue is that HCL uses the same syntax for its own variables. In snippet example 'three', the output should contain the literal string ${var.s3_bucket_name} but I guess that throws parsing errors? I've never worked with snippets beyond just using them. I hit a parsing error on this one today which initiated my search to find this issue.

From what I understand based on the snippet grammar documentation, the snippet I'm using is likely failing to parse because of the line " ami_id = \"${var.ami_id}\"",? Since I would want the literal ${var.ami_id} to be contained in the output of the snippet, it should be written instead as " ami_id = \"\${var.ami_id}\"", with the \ in front of the $?

Hopefully my understanding is correct. I'll try and take a stab at it when I can find some spare time this week.

@echasnovski
Copy link
Contributor Author

Ah, so are most of the instances of ${var.ami_id} and similar meant to be inserted literally as that text? Sorry, I am completely not familiar with terraform.

If this is correct, then yes, it at least should be represented in Lua as "\\${var.ami_id}" or [[\${var.ami_id}]]. But judging by the grammar in LSP specification the } should also be escaped (so it becomes "\\${var.ami_id\\}"). Not sure if all snippet engines support the latter though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants