Skip to content

fix: pass strip_string_quotes to hcl2.load() for python-hcl2 v8.x compat#96

Merged
bentsku merged 2 commits intomainfrom
fix-tflocal
Apr 13, 2026
Merged

fix: pass strip_string_quotes to hcl2.load() for python-hcl2 v8.x compat#96
bentsku merged 2 commits intomainfrom
fix-tflocal

Conversation

@HarshCasper
Copy link
Copy Markdown
Member

Summary

  • python-hcl2 v8.x wraps all parsed string keys/values in literal quotes characters by default, which broke AWS provider version detection from the lock file
  • This caused iotanalytics and iotevents endpoints to always be included in the generated override file, even for AWS provider v6.x
    where they were removed
  • Fix: pass SerializationOptions(strip_string_quotes=True) to all
    hcl2.load() calls in both bin/tflocal and tests/test_apply.py

@alexrashed alexrashed requested review from dominikschubert and removed request for alexrashed April 13, 2026 09:01
Copy link
Copy Markdown
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for jumping on this! I believe there was a community contribution that had started to fix this as well with #94

Do you think it'd be possible to cherry pick their commit to keep their contribution, as they also updated the changelog and the requirements which are missing from this PR? 👍

Let me know if you'd like me to cherry pick that commit, I can do it, merge then do a release

Hoffs and others added 2 commits April 13, 2026 15:52
…l2 v8 compat

strip_string_quotes alone is not sufficient — python-hcl2 v8 also injects
__is_block__ and __comments__ metadata keys into parsed dicts, which leak
into generated .tf override files causing "argument not expected" errors.

Also update tests to use the same SerializationOptions when parsing
override files.
Copy link
Copy Markdown
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing the comments so quickly! I'll comment on #94 to follow-up 👍

I'll merge and do a release, this repo is a also a prime target for a tag-based workflow 👍

Comment thread bin/tflocal
Comment on lines +29 to +31
from hcl2 import SerializationOptions # noqa: E402

HCL2_SERIALIZATION_OPTIONS = SerializationOptions(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mostly a note for later and not something actionable for this PR: I don't know if we explicitly set some versions on hcl2 for some reasons, and if we're aiming of compatibility. There could be a world when we want to keep compatibility with older versions, and would have to try to import the SerializationOptions and fallback if it failed, and pass some kwargs to load.

But I think hcl2>=8 is just the right version to use, so we can see later, I think we'll need to rework how we package this!

@bentsku bentsku merged commit 3e8f905 into main Apr 13, 2026
3 checks passed
@bentsku bentsku deleted the fix-tflocal branch April 13, 2026 10:53
@bentsku bentsku mentioned this pull request Apr 13, 2026
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

Successfully merging this pull request may close these issues.

3 participants