-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform output and console show multi-line strings with an additional newline #31657
Comments
Thanks for the bug report! |
I can see this in the docs: A heredoc string consists of:
This info is located here. @crw - so the trailing new line is expected, right ? or am I misunderstanding the issue. |
Actual output of the example mentioned in the issue:
Expected :
|
@SamrathPalSingh I'm not sure, I think it depends if you think |
The definitive answer: it is a part of the HCL implementation/spec that the newline at the end of each line of a HEREDOC is preserved exactly. It is a quirk of our CLI value rendering that we render multi-line strings by pretending it's a HEREDOC, as part of our mission to show values in the UI in a similar way to how users would read them in the configuration. This abstraction leaks a little here because there isn't any way to write a HEREDOC without a trailing newline in HCL. We could potentially change it to return a single-line quoted string with Given the above, it might make sense to document this behavior so that it is not a surprise. That said, I'm not entirely sure where this documentation would go, since it is less to do with HEREDOC usage and more to do with a quirk of how it is output. In any case, I will flag it as a documentation issue and raise it with the docs team. Thanks for the feedback on this! |
In our own tooling that generates HCL, we're planning to use Is it possible to do something similar in the terraform console output? (since the current representation isn't accurate) |
The choice to render multi-line strings as HEREDOC is a quirk of Terraform CLI, and the rendering has to end with a newline (that may not exist!) to fit the HEREDOC format. Per the previous comment, the choice would seem to be between getting rid of the HEREDOC formatting entirely in favor of a less-human-readable format (e.g. |
I understand and agree that HEREDOC is more readable. My suggestion was to keep using HEREDOC but add a
That way it's correct if copy+pasted, and maintains readability. I think documentation wouldn't have helped me unless it was inline in the output. |
That is more clear. Thanks for your feedback! |
Terraform Version
Terraform Configuration Files
Expected Behavior
When running
terraform apply
, the output variable is printed to the console correct;lyActual Behavior
After running
terraform apply
, it prints the output variable with an additional newline:If I take the exact same heredoc and use it for the v1 variable, the output file has a trailing newline (which the value "foo\nbar" does not).
Additional Context
The same issue occurs in the console, it shows an additional newline for multi-line strings
The text was updated successfully, but these errors were encountered: