使用 Terraform 创建 Filebeat 配置
Creating Filebeat configuration with Terraform
我正在尝试在使用 Terraform 创建实例后创建一个 Filebeat 配置文件:
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 配置的一部分并抛出错误。
如何将 path: '$'{path.config}/modules.d/*.yml
作为字符串传递?
您需要用双倍美元 ($$
) 转义文字美元 ($
)。
interpolation documentation 包括以下内容:
You can escape interpolation with double dollar signs: $${foo} will be rendered as a literal ${foo}.
在 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.
我正在尝试在使用 Terraform 创建实例后创建一个 Filebeat 配置文件:
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 配置的一部分并抛出错误。
如何将 path: '$'{path.config}/modules.d/*.yml
作为字符串传递?
您需要用双倍美元 ($$
) 转义文字美元 ($
)。
interpolation documentation 包括以下内容:
You can escape interpolation with double dollar signs: $${foo} will be rendered as a literal ${foo}.
在 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.