Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform, Looking for a simple way to use double quotation marks in commands?

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",
    ]
}
like image 731
Alex Cohen Avatar asked Jun 16 '16 20:06

Alex Cohen


People also ask

How do you insert a double quote?

Double quotation marks on WindowsPress-and-hold the ALT key and then type 0147 for the opening single quotation mark and ALT followed by 0148 for the closing single quotation mark.

How do you pass a double quote in a string?

If you need to use the double quote inside the string, you can use the backslash character. Notice how the backslash in the second line is used to escape the double quote characters. And the single quote can be used without a backslash.

Can char use double quotes?

Use the CHAR functionYou can also insert a double quote in an Excel formula using the CHAR function.


1 Answers

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"
like image 165
ydaetskcoR Avatar answered Nov 12 '22 00:11

ydaetskcoR