使用 Terraform 创建 Filebeat 配置 [英] Creating Filebeat configuration with Terraform
问题描述
我正在尝试在使用 Terraform 创建实例后创建 Filebeat 配置文件:
I am trying to create a Filebeat configuration file after creating a instance with Terraform:
resource "local_file" "greylogIP" {
content = <<EOF
filebeat.inputs:
- type: log
enabled: false
paths:
- /var/log/*.log
filebeat.config.modules:
path: '$'{path.config}/modules.d/*.yml
reload.enabled: false
setup.template.settings:
index.number_of_shards: 3
output.logstash:
hosts: ["${aws_instance.web.public_ip}:5014"]
EOF
filename = "filebeat.conf"
}
我需要传递 ${aws_instance.web.public_ip}
变量来分配动态 IP,但 Terraform 也尝试插入 path: '$'{path.config}/modules.d/*.yml
这是 Filebeat 配置的一部分,会抛出错误.
where I need to pass the ${aws_instance.web.public_ip}
variable to allocate the dynamic IP but some how Terraform is also trying to interpolate path: '$'{path.config}/modules.d/*.yml
which is a part of the Filebeat configuration and throws an error.
如何将 path: '$'{path.config}/modules.d/*.yml
作为字符串传递?
How can I pass the path: '$'{path.config}/modules.d/*.yml
as a string instead?
推荐答案
您需要使用双美元 ($$
) 转义文字美元 ($
).
You need to escape a literal dollar ($
) with a double dollar ($$
).
插值文档涵盖了这一点:
您可以使用双美元符号转义插值:$${foo} 将呈现为文字 ${foo}.
You can escape interpolation with double dollar signs: $${foo} will be rendered as a literal ${foo}.
重要提示:内联模板中的模板变量(例如上面的 consul_address)必须用双 $ 转义.Terraform 通常会在执行模板之前处理未转义的插值.
Important: Template variables in an inline template (such as consul_address above) must be escaped with a double-$. Unescaped interpolations will be processed by Terraform normally prior to executing the template.
这篇关于使用 Terraform 创建 Filebeat 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!