Creating Filebeat configuration with Terraform

☆樱花仙子☆ 提交于 2019-12-13 17:25:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!