fix: heredocs_to_strings writes a value, not the heredoc's text (#337) - #351
Draft
livingstaccato wants to merge 1 commit into
Draft
fix: heredocs_to_strings writes a value, not the heredoc's text (#337)#351livingstaccato wants to merge 1 commit into
livingstaccato wants to merge 1 commit into
Conversation
…ify-education#337) The option converts a heredoc into a quoted string, and was quoting the heredoc's own source -- markers and all -- across as many physical lines as the original occupied: a = "<<EOT hello EOT" A quoted template cannot span lines. OpenTofu rejects that with "Invalid multi-line string", and reading it back here gave the marker text rather than the value, so the option produced neither a valid file nor the right content. It is exposed on the shipped `jsontohcl2` script, so the CLI had the same hole. The flattening the reader already performs is reused rather than written a second time: serializing the rule with `preserve_heredocs=False` is exactly the quoted form that option produces on the way in, so the two cannot drift apart the way the escape alphabets did. The value that form carries is the reader's, which on this branch still drops the body's trailing newline -- that is amplify-education#326, and this change follows whatever the reader does rather than second-guessing it.
Contributor
Author
|
Please hold off on merging this one for now — I want to do another review pass over it before it goes in. Opened as a draft for that reason; I will mark it ready and say so here once I am done. |
This was referenced Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #337.
What
The option converts a heredoc into a quoted string, and was quoting the heredoc's own source — markers and all — across as many physical lines as the original occupied:
A quoted template cannot span lines. OpenTofu rejects that with "Invalid multi-line string", and reading it back here gives
'<<EOT\nhello\nEOT'— the marker text rather than the value. So the option produced neither a valid file nor the right content, and it is exposed on the shippedjsontohcl2script, so the CLI had the same hole.After:
How
By reusing the flattening the reader already performs, rather than writing a second one: serializing the rule with
preserve_heredocs=Falseis exactly the quoted form that option produces on the way in. The two therefore cannot drift apart the way the escape alphabets did in #329 — there is only one implementation of "what is this heredoc as a quoted string".What that inherits
The value carried is the reader's. On
mainthat still drops the body's trailing newline, so<<EOT\nhello\nEOTbecomes"hello"where Terraform reads"hello\n". That is #326, fixed in #335, and this change deliberately follows whatever the reader does rather than second-guessing it — when #335 lands, this output gains the newline with no change here.Eight tests, including that every converted form parses again and that no marker survives into the output.
Merging
It touches the same code as #346 (
hcl2/deserializer.py), #354 (hcl2/deserializer.py). Whichever of those lands first, this one needs a rebase rather than a merge — the overlaps are real edits to the same methods, not adjacent lines, so resolving them by hand risks losing one of the two fixes. Say the word and I will rebase and re-run the suite.This pull request, and the investigation behind it, were produced by an AI assistant (Claude) working on behalf of the author. Every reproduction, test run and benchmark cited was executed rather than inferred, but please review with that provenance in mind.