【问题标题】:quote around the output value using terraform "local-exec" provisioner使用 terraform "local-exec" 配置器引用输出值
【发布时间】:2017-07-20 11:21:22
【问题描述】:

我想在输出值周围加上引号(简单地说,我想使用“local-exec”配置程序将输出写入文件,但不幸的是它没有在它周围加上引号,尽管它确实回显了正确的文件的价值。我也使用了转义字符 () 但仍然没有运气。任何帮助将不胜感激。谢谢

代码 sn-p 供参考:

provisioner "local-exec" {
command = " echo **ELB_DNS_NAME: \"${aws_elb.elb.dns_name}\"** >> ${var.name}.yml"
}

【问题讨论】:

    标签: terraform


    【解决方案1】:

    我不确定这是否是最简单或最理想的解决方案,但我想多行字符串语法应该可以工作,如 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}"
    }
    

    【讨论】:

      【解决方案2】:

      使用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"
        }
      }
      

      在&lt;your root TF directory&gt;/templates/name.tpl 中,您只需:

      **ELB_DNS_NAME: "${elb_dns_name}"**
      

      【讨论】:

        猜你喜欢
        • 2019-10-21
        • 2020-07-01
        • 2020-07-07
        • 2016-11-28
        • 1970-01-01
        • 1970-01-01
        • 2015-11-26
        • 2020-07-09
        • 1970-01-01
        相关资源
        最近更新 更多