Skip to content

fix: Use valid syntax for conditionals (#254)#258

Closed
kkozik-amplify wants to merge 2 commits intomainfrom
tmccombs/conditional-fix
Closed

fix: Use valid syntax for conditionals (#254)#258
kkozik-amplify wants to merge 2 commits intomainfrom
tmccombs/conditional-fix

Conversation

@kkozik-amplify
Copy link
Collaborator

@kkozik-amplify kkozik-amplify commented Feb 12, 2026

by @tmccombs:

  • fix: Use valid syntax for conditionals

Fix an issue where object literals inside conditional expressions were not rendered correctly, resulting in invalid expresions.

* fix: Use valid syntax for conditionals

Fix an issue where object literals inside conditional expressions were not rendered
correctly, resulting in invalid expresions.
@kkozik-amplify kkozik-amplify requested a review from a team as a code owner February 12, 2026 16:59
@kkozik-amplify kkozik-amplify marked this pull request as draft February 19, 2026 11:55
@kkozik-amplify
Copy link
Collaborator Author

kkozik-amplify commented Feb 19, 2026

Hey @tmccombs
I added round-trip test case in this commit based on the actual vs expected behavior you described in #253 and it doesn't pass.
Seems like your proposal wraps objects key in double quotes, which I don't believe is correct/expected inside an inline representation

@tmccombs
Copy link

which I don't believe is correct/expected inside an inline representation

Maybe I'm misunderstanding what you are saying, but why do you think that?

@tmccombs
Copy link

Here's a tofu console showing that using quoted strings in keys in inline objects is fine:
image

And if that isn't ok, that seems like a bug in how the to_tf_inline method serializes a dict.

@kkozik-amplify
Copy link
Collaborator Author

For example

  providers = {
    "aws.ue1" = aws
    aws.uw2 = aws.backup
  }

quoted references have been officialy deprecated.

Besides that, the library should still transform HCL2 to JSON faithfully without syntactic changes.

@kkozik-amplify
Copy link
Collaborator Author

that seems like a bug in how the to_tf_inline method serializes a dict.

Yeah this might be the case. If you would want to try pushing a fix for this, you could open a new PR to this branch. Otherwise let me know if I should close this PR.

@tmccombs
Copy link

quoted references have been officialy deprecated.

Do you have a source for that? I wasn't able to find anything.

@tmccombs
Copy link

FWIW, other epxressions with inline objects currently use double quotes as well:

>>> import hcl2
>>> hcl2.loads("""
... a {
...   x = merge({a = 2, b = "hello"}, var.more)
... }
... """)
{'a': [{'x': '${merge({"a": 2, "b": "hello"}, var.more)}'}]}

So, this change isn't really changing anything around that.

That said, is there any reason why to_tf_inline doesn't just do something like hcl2.writes(hcl2.reverse_transform(value))?

@kkozik-amplify kkozik-amplify added fixed-in-8.0 available-in-prerelease fixed in the latest pre-release version. Install with: pip install python-hcl2 --pre --upgrade and removed fixed-in-8.0 labels Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

available-in-prerelease fixed in the latest pre-release version. Install with: pip install python-hcl2 --pre --upgrade

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants