Summary
The option converts a heredoc into a quoted string, but writes the heredoc's
source -- markers and all -- inside the quotes, across as many physical lines
as the original occupied. A quoted template cannot span lines, so the result is
not readable by Terraform, and reading it back with this library gives the
marker text rather than the value.
Reproduction
import hcl2
from hcl2.deserializer import DeserializerOptions
hcl2.dumps(
hcl2.loads("a = <<EOT\nhello\nEOT\n"),
deserializer_options=DeserializerOptions(heredocs_to_strings=True),
)
OpenTofu rejects that with "Invalid multi-line string / Quoted strings may not
be split over multiple lines", although the input file evaluates to "hello\n".
Reading it back here yields '<<EOT\nhello\nEOT', so the option produces
neither a valid file nor the right value.
The field is DeserializerOptions.heredocs_to_strings
(hcl2/deserializer.py:73 at v8.1.3), read at :171 and :176, and it is
exposed on the shipped jsontohcl2 console script as --heredocs-to-strings
(cli/json_to_hcl.py:176, confirmed in jsontohcl2 --help).
Suggested shape of the fix
Convert the heredoc's value and escape it for a quoted string -- hello\n
becomes "hello\n" with the newline written as an escape -- rather than
quoting the source text.
This issue, and the investigation behind it, were produced by an AI assistant (Claude) working on behalf of the author. Please review with that provenance in mind.
Summary
The option converts a heredoc into a quoted string, but writes the heredoc's
source -- markers and all -- inside the quotes, across as many physical lines
as the original occupied. A quoted template cannot span lines, so the result is
not readable by Terraform, and reading it back with this library gives the
marker text rather than the value.
Reproduction
OpenTofu rejects that with "Invalid multi-line string / Quoted strings may not
be split over multiple lines", although the input file evaluates to
"hello\n".Reading it back here yields
'<<EOT\nhello\nEOT', so the option producesneither a valid file nor the right value.
The field is
DeserializerOptions.heredocs_to_strings(
hcl2/deserializer.py:73atv8.1.3), read at:171and:176, and it isexposed on the shipped
jsontohcl2console script as--heredocs-to-strings(
cli/json_to_hcl.py:176, confirmed injsontohcl2 --help).Suggested shape of the fix
Convert the heredoc's value and escape it for a quoted string --
hello\nbecomes
"hello\n"with the newline written as an escape -- rather thanquoting the source text.
This issue, and the investigation behind it, were produced by an AI assistant (Claude) working on behalf of the author. Please review with that provenance in mind.