使用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屋!