Terraform,寻找在命令中使用双引号的简单方法?

时间:2016-06-16 20:53:08

标签: provisioning terraform

我需要一种在我的terraform脚本的"块中使用常规引号provisioner "remote-exec"的简单方法。只有"才能满足我的目标,只需尝试\"即可。什么是最简单的方法让terraform从字面上解释我的命令。这里是我想要运行的参考:

provisioner "remote-exec" {
    inline = [
      "echo 'DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"' > /etc/default/docker",
    ]
}

1 个答案:

答案 0 :(得分:8)

使用反斜杠转义对我来说很好用:

$ cat main.tf

resource "null_resource" "test" {
    provisioner "local-exec" {
        command = "echo 'DOCKER_OPTS=\"-H tcp://0.0.0.0:2375\"' > ~/terraform/37869163/output"
    }
}

$ terraform apply .

null_resource.test: Creating...
null_resource.test: Provisioning with 'local-exec'...
null_resource.test (local-exec): Executing: /bin/sh -c "echo 'DOCKER_OPTS="-H tcp://0.0.0.0:2375"' > ~/terraform/37869163/output"
null_resource.test: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

...

$ cat output

DOCKER_OPTS="-H tcp://0.0.0.0:2375"