Skip to content

Conversation

@dsa0x
Copy link
Member

@dsa0x dsa0x commented Mar 10, 2025

Fixes #36652

When a string interpolation contains only one expression sequence, HCL optimizes by wrapping and directly delegating evaluation to that expression. The templatestring function tries to refine the expression value as non-null, and if null, this refinement leads to a panic. For compatibility reasons, HCL has to continue to support this unwrapping logic (See attempted PR), thus we will simply return an error in templatestring when the single evaluated expression is null

Target Release

1.12.x

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@dsa0x dsa0x marked this pull request as ready for review March 10, 2025 08:59
@dsa0x dsa0x requested a review from a team as a code owner March 10, 2025 08:59
SarahFrench
SarahFrench previously approved these changes Mar 10, 2025
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: Return error when the template's single interpolation results in null value
Copy link
Member

Choose a reason for hiding this comment

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

Could you please update the change file to mention the templatestring function?

@dsa0x dsa0x merged commit 08fa94c into main Mar 10, 2025
8 checks passed
@dsa0x dsa0x deleted the sams/fix-single-wrapped-null branch March 10, 2025 11:38
@dsa0x dsa0x added the 1.11-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Mar 10, 2025
@github-actions
Copy link
Contributor

Changelog Warning

Currently this PR would target a v1.11 release. Please add a changelog entry for in the .changes/v1.11 folder, or discuss which release you'd like to target with your reviewer. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.

@dbanck
Copy link
Member

dbanck commented Mar 10, 2025

Heads up, the changelog for this change has ended up in the wrong folder and wrong branch. Since it was backported to 1.11, there should only be a changelog file on the v1.11 branch in the .changes/1.11 directory. None on main

@dsa0x
Copy link
Member Author

dsa0x commented Mar 10, 2025

Thanks @dbanck. I'll move appropriately

wata727 added a commit to terraform-linters/tflint that referenced this pull request Mar 28, 2025
wata727 added a commit to terraform-linters/tflint that referenced this pull request Mar 28, 2025
* Avoid crash due to map with `null` values

Follow up of hashicorp/terraform#36611

* Update Terraform compatibility guide

* Return error when the template's single interpolation results in null value

Follow up of hashicorp/terraform#36658

* Bump patch version
@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, 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 Apr 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

1.11-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

templatestring Function Crashes When Map Contains a Key Mapped to null

3 participants