我想把引号放在输出值附近(简单来说,我想使用“local-exec”配置器将输出写入文件但不幸的是它没有把引号括在它周围虽然它确实回应了正确的文件的值。我也使用了转义字符()但仍然没有运气。任何帮助都将非常感谢。谢谢
参考代码段:
provisioner "local-exec" {
command = " echo **ELB_DNS_NAME: \"${aws_elb.elb.dns_name}\"** >> ${var.name}.yml"
}
答案 0 :(得分:0)
我不确定这是否是最简单或最理想的解决方案,但我认为多行字符串语法应该可行,如here所示,并记录here。
resource "aws_iam_user_policy" "lb_ro" {
name = "test"
user = "${aws_iam_user.lb.name}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_user" "lb" {
name = "loadbalancer"
path = "/system/"
}
resource "aws_iam_access_key" "lb" {
user = "${aws_iam_user.lb.name}"
}
答案 1 :(得分:0)
使用template_file
data source和file
provisioner,这样您就不必乱用引用/转义字符。
data "template_file" "name" {
template = "${file("${path.root}/templates/name.tpl")}"
vars {
elb_dns_name = "${aws_elb.elb.dns_name}"
}
}
[...]
resource "null_resource" "render_templates"
provisioner "file" {
content = "${data.template_file.name.rendered}"
destination = "name.yml"
}
}
在<your root TF directory>/templates/name.tpl
你只需要:
**ELB_DNS_NAME: "${elb_dns_name}"**