我有一个模板文件,它正在创建一个 fluentd 文件并插入各种变量。我现在试图包含这个插件 ,它希望在配置文件中找到它自己的变量。问题是 Terraform 在模板中定义了一个变量${variable},这个插件希望在文件中找到它的变量作为文字${variable}
如何告诉 terraform 不要${}在文件中插入 a ,而是实际传递整个字符串?
文件片段:
<filter tomcat.logs>
@type record_transformer
<record>
customer ${customer}
environment ${environment}
application ${application}
</record>
</filter>
Run Code Online (Sandbox Code Playgroud)
以上${}是我为模板定义的所有变量。我现在需要添加一个这样的部分。
<record>
hostname ${tagset_name}
instance_id ${instance_id}
instance_type ${instance_type}
az ${availability_zone}
private_ip ${private_ip}
vpc_id ${vpc_id}
ami_id ${image_id}
account_id ${account_id}
</record>
Run Code Online (Sandbox Code Playgroud)
所有这些都是不变量,但它是如何实际需要渲染的模板的样子。我尝试将它们交换为 like $${account_id},但这最终只会在文件中呈现 account_id 。
data "template_file" "app" {
template = "${file("templates/${var.application}.tpl")}"
vars {
customer = "${var.customer}"
environment = "${var.environment}"
application = "${var.application}"
}
}
Run Code Online (Sandbox Code Playgroud)
这是正在发生的事情的细分。
In the user data I have "instance_type $${instance_type}"
The launch configuration that is created for the instances, shows "instance_type ${instance_type}"
The actual file that is present on AWS shows "instance_type"
Run Code Online (Sandbox Code Playgroud)
终于想通了这一点。对于此实例,标记重复问题的答案不正确。
template.tpl 包含
cat <<EOT > /root/test.file
db.type=${db_type}
instance_type \$${instance_type}
EOT
Run Code Online (Sandbox Code Playgroud)
结果
Error: Error refreshing state: 1 error(s) occurred:
* module.autoscaling_connect.data.template_file.app: 1 error(s) occurred:
* module.autoscaling_connect.data.template_file.app: data.template_file.app: failed to render : 27:16: unknown variable accessed: bogus_value
Run Code Online (Sandbox Code Playgroud)
template.tpl 包含
cat <<EOT > /root/test.file
db.type=${db_type}
instance_type \$${instance_type}
EOT
Run Code Online (Sandbox Code Playgroud)
结果包含在启动配置中
cat <<EOT > /root/test.file
db.type=mysql
instance_type \${instance_type}
EOT
Run Code Online (Sandbox Code Playgroud)
结果我们在实例上创建的文件包含
db.type=mysql
instance_type ${instance_type}
Run Code Online (Sandbox Code Playgroud)
总之,要${something}在从 terraform 模板文件创建的文件中结束,您必须\$${something}在 .tpl 文件中使用。
| 归档时间: |
|
| 查看次数: |
2883 次 |
| 最近记录: |