Terraform:flatcar OS的容器linux配置的存储部分中的YAML文件呈现问题
我试图通过模板渲染生成一个文件,以传递给ec2实例的用户数据。我正在使用第三方terraform提供程序从YAML生成点火文件Terraform:flatcar OS的容器linux配置的存储部分中的YAML文件呈现问题,terraform,coreos-ignition,Terraform,Coreos Ignition,我试图通过模板渲染生成一个文件,以传递给ec2实例的用户数据。我正在使用第三方terraform提供程序从YAML生成点火文件 data "ct_config" "worker" { content = data.template_file.file.rendered strict = true pretty_print = true } example.yml storage: files: - path: "/opt/bin/script"
data "ct_config" "worker" {
content = data.template_file.file.rendered
strict = true
pretty_print = true
}
example.yml
storage:
files:
- path: "/opt/bin/script"
mode: 0755
contents:
inline: |
${script}
错误:
Error: Error unmarshaling yaml: yaml: line 187: could not find expected ':'
on ../../modules/launch_template/launch_template.tf line 22, in data "ct_config" "worker":
22: data "ct_config" "worker" {
如果我将${script}
更改为示例数据,那么它会工作。另外,无论我在script.sh中输入了什么,我都会得到相同的错误。您想要这个结果(伪代码):
在当前实现中,第一次从script.sh加载之后的所有行都不会缩进,也不会由YAML解码器按需要解释(整个script.sh内容)
使用可以更正缩进,使用较新的功能,可以对模板使用稍微干净的设置:
data "ct_config" "worker" {
content = local.ct_config_content
strict = true
pretty_print = true
}
locals {
ct_config_content = templatefile("${path.module}/example.yml", {
script = indent(10, file("${path.module}/script.sh"))
})
}
为清楚起见,下面是example.yml模板文件(来自原始问题),用于上面的代码:
storage:
files:
- path: "/opt/bin/script"
mode: 0755
contents:
inline: |
${script}
我在
ct\u config
中遇到了这个问题,今天就解决了。您需要对脚本进行base64encode
编码,以确保在没有换行符的情况下正确编写脚本-否则,脚本中的换行符将发送到CT,CT将尝试构建一个点火文件,该文件不能包含换行符,从而导致您最初遇到的错误
编码后,您只需告诉CT!!二进制文件
确保点火正确的文件base64在部署时对其进行解码:
data "template_file" "file" {
...
...
template = file("${path.module}/example.yml")
vars = {
script = base64encode(file("${path.module}/script.sh"))
}
}
您希望
${script}
的值是多少?我已经更新了这个问题。无论内容如何,我都会收到一个错误。但是,我希望${script}
包含我文件的内容。此答案似乎不起作用。@admdraw您遇到了什么错误?@admdraw请注意,此答案希望您使用问题中显示的example.yml。我的回答中的YAML是所需输出的psuedocode,不能用作模板。这是一个特别的问题(提供OP在其示例中列出的ct\u config
数据源的内容),是点火配置的换行问题,而不是缩进问题。@admdraw请再次查看该问题。发布的错误是Terraform中的直接解组问题。我发布的补丁地址是。此外,ct_配置也会传输到Ignition,因此我不确定提供商为什么不解决您确定的第二个订单问题。谢谢你的参与。你在哪里找到新行限制的文件?
storage:
files:
- path: "/opt/bin/script"
mode: 0755
contents:
inline: |
${script}
data "template_file" "file" {
...
...
template = file("${path.module}/example.yml")
vars = {
script = base64encode(file("${path.module}/script.sh"))
}
}
storage:
files:
- path: "/opt/bin/script"
mode: 0755
contents:
inline: !!binary |
${script}