Terraform:heredoc 锚点中的无效字符 [英] Terraform: invalid characters in heredoc anchor
问题描述
我正在尝试在我的 terraform 脚本的 provisioner "remote-exec"
块中使用多行字符串.然而,每当我使用文档和各种示例中概述的 EOT
语法时,我都会收到一个错误,抱怨有:heredoc 锚中的无效字符
.
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
.
以下是收到此错误的简单 provisioner "remote-exec"
示例(两种类型的 EOT 在单独尝试时都会收到此错误):
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,
]
}
更新:这是可行的解决方案,如果您遇到此问题,请仔细阅读,因为 terraform 在 EOF 方面非常挑剔:
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
]
}
请注意,如果您想使用 EOF,则在 provisioner "remote-exec"
块中使用的所有命令都必须在 EOF 内.您不能同时拥有 EOF 和非 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.
EOF 的第一行必须这样开始,并且在 <<EOF
之后的这一行中不能有任何空格,否则它会抱怨有 heredoc 锚中的无效字符
:
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
你的 EOF 必须像这样以 EOF
结尾,与 ]
Your EOF must then end like this with the EOF
at the same indentation as the ]
EOF
]
推荐答案
Terraform 中的Heredocs 对周围的空白特别有趣.
Heredocs in Terraform are particularly funny about the surrounding whitespace.
将您的示例更改为以下内容似乎可以消除heredoc 特定的错误:
Changing your example to the following seems to get rid of the heredoc specific errors:
provisioner "remote-exec" {
inline = [<<EOF
echo hi
EOF,
<<EOF
echo
hi
EOF
]
}
尽管内联数组是应在远程主机上运行的命令列表,但您根本不需要在此处使用多个 heredocs.使用带有多行命令的 heredoc 对您来说应该可以正常工作:
You shouldn't need multiple heredocs in here at all though as the inline array is a list of commands that should be ran on the remote host. Using a heredoc with commands across multiple lines should work fine for you:
provisioner "remote-exec" {
inline = [<<EOF
echo foo
echo bar
EOF
]
}
这篇关于Terraform:heredoc 锚点中的无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!