8

I need a simple way of using regular quotations " in the provisioner "remote-exec" block of my terraform script. Only " will work for what I would like to do and just trying \" doesn't work. Whats the easiest way to have terraform interpret my command literally. For reference here is what I am trying to run:

provisioner "remote-exec" {
    inline = [
      "echo 'DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"' > /etc/default/docker",
    ]
}
Alex Cohen
  • 5,596
  • 16
  • 54
  • 104
  • 2
    Maybe you could just use the file provisioner and do this with a shell script instead. A bit more overhead, but at least it's easier/cleaner to build upon in the future. – Jocke Jul 06 '16 at 09:37

1 Answers1

17

Escaping with backslashes works fine for me:

$ 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"
ydaetskcoR
  • 53,225
  • 8
  • 158
  • 177