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

HCL interpolations within dict output contain single quotes #172

Open
weaversam8 opened this issue Oct 9, 2024 · 2 comments
Open

HCL interpolations within dict output contain single quotes #172

weaversam8 opened this issue Oct 9, 2024 · 2 comments

Comments

@weaversam8
Copy link
Contributor

HCL only supports double quotes, but some interpolations may contain single quotes.

Example hcl:

block {
  type = list(
    object({
      id = string
    })
  )
}

Expected output:

{'block': [{'type': "${list(object({\"id\": \"${string}\"}))}", '__start_line__': 1, '__end_line__': 7}]}

Actual output (note the difference in quotes):

{'block': [{'type': "${list(object({'id': '${string}'}))}", '__start_line__': 1, '__end_line__': 7}]}

I plan to fix this in a future PR, just creating this issue for tracking purposes.

@weaversam8
Copy link
Contributor Author

This is actually true for many different Python datatypes - booleans appear in this output as True and False instead of the Terraform true and false.

weaversam8 added a commit to weaversam8/python-hcl2 that referenced this issue Oct 11, 2024
@eravin-duo
Copy link

eravin-duo commented Oct 17, 2024

Thank you for maintaining this project, it has been a great help for my work!

I think I'm hitting this bug or something similar. I have a Terraform file with stuff like this in it:

SOMETHING_LIST = [for v in values({ for k, v in module.something.or_other : v["x"] => v["y"]... }) : v[0]]

When I parse the file with the hcl2 library it gave me this value:

${[for v in values({ for k, v in module.something.or_other : v["x"] => v["y"]... }) : v[0]]}

I added some code to remove the ${ } stuff and all was well until today, when I noticed the parse result now looks like this:

['${[for v in values({ for k, v in module.something.or_other : v["x"] => v["y"]... }) : v[0]]}']

In other words, I'm getting not only the unwanted ${ } but also an additional [' '] around the parse result.

After digging around and finding a different environment without the problem, I realized that the broken environment had lark 1.1.9 while the working one had lark 1.2.2. So I'm back to the first case with just the ${ } stuff.

I hope this data point is useful.

weaversam8 added a commit to weaversam8/python-hcl2 that referenced this issue Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants