End of stream delimiters showing up in output

Problem
I am receiving outputs which contain the <<EOT and EOT delimiter, for an unknown reason. It only appears in the outputs for which I use the random_password resource on.

Example Input

resource “random_password” “http-cs-teamserver-password” {
count = 2
length = 15
special = true
override_special = “@%)-_+[}:”
}
output “dns-cs-teamserver-passwords” {
value = join(“\n”, random_password.dns-cs-teamserver-password[*].result)
}

Example Output

dns-cs-teamserver-passwords = <<EOT
-@GoESLjwrgXE4F
_PfWDI[zJ:yS5Sb
EOT

Is there a way to fix this minor issue? I can upload an image of the stdout output if needed.
Thank you for your time!

What do you want to achieve?

If you compare it with terraform output -json it makes sense to have an end for start/end of the output.

there’s even a -raw <output> option with later terraform versions.

@tbugfinder
Running the JSON output made me realize that I was a constructing a string for no reason, and your question of what I was trying to accomplish made me realize I merely wanted an array with the underlying strings contained inside and that the join operation could be completely eliminated, giving:

output “dns-cs-teamserver-passwords” {
value = random_password.dns-cs-teamserver-password[*].result
}

and outputting (what I needed):

dns-cs-teamserver-passwords = [
“O_J%-B[IAfjga59”,
“L%pN5Y0HPxCHtt7”,
]

Thank you for your time, as always!

I’m glad you found a workable answer!

I just wanted to add the answer to your original question as stated, even though I think it wasn’t significant in the end: when Terraform prints values out for human consumption it has a few heuristics to try to make them more readable in common cases, and one of those heuristics is that it will use a presentation resembling the multi-line “heredoc” string if the value being rendered is a string with newline characters in it.

That’s intended to make it more likely to be readable when the string represents something like the contents of a templated shell script, or similar. It’s debatable whether it was a good heuristic for your case here, but part of the nature of a heuristic like this is that it won’t always do the most ideal thing, especially when “the most ideal thing” is subjective as in this case.

1 Like