I am trying to use a multiline string in the provisioner "remote-exec"
block of my terraform script. Yet whenever I use the EOT
syntax as outlined in the documentation and various examples I get an error that complains about having: invalid characters in heredoc anchor
.
Here is an example of a simple provisioner "remote-exec"
that received this error (both types of EOT receive this error when attempted separately):
provisioner "remote-exec" {
inline = [
<< EOT
echo hi
EOT,
<< EOT
echo \
hi
EOT,
]
}
Update: Here is the working solution, read carefully if you are having this issue because terraform is very picky when it comes to EOF:
provisioner "remote-exec" {
inline = [<<EOF
echo foo
echo bar
EOF
]
}
Note that if you want to use EOF all the commands you use in a provisioner "remote-exec"
block must be inside the EOF. You cannot have both EOF and non EOF its one or the other.
The first line of EOF must begin like this, and you cannot have any whitespace in this line after <<EOF
or else it will complain about having invalid characters in heredoc anchor
:
inline = [<<EOF
Your EOF must then end like this with the EOF
at the same indentation as the ]
EOF
]
The here-document end-delimiter has a comma (,
) at the end. That's not allowed.
Try this instead:
provisioner "remote-exec" {
inline = [
<<EOT
echo hi
EOT
,
<<EOT
echo \
hi
EOT
,
]
}
I'm unaware of the syntax requirements of the file, but a here-document end-delimiter needs to match the word used at its start.
Also, usually (in shells), the delimiter needs to come first on the line (no whitespace in front).
In fact, the Terraform documentation says this:
Multiline strings can use shell-style "here doc" syntax, with the string starting with a marker like
<<EOT
and then the string ending withEOT
on a line of its own. The lines of the string and the end marker must not be indented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With