问题
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"
}
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.
How can I pass the path: '$'{path.config}/modules.d/*.yml
as a string instead?
回答1:
You need to escape a literal dollar ($
) with a double dollar ($$
).
The interpolation documentation covers this:
You can escape interpolation with double dollar signs: $${foo} will be rendered as a literal ${foo}.
There's some further mention of it in the template docs:
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.
来源:https://stackoverflow.com/questions/51971666/creating-filebeat-configuration-with-terraform