2

I am attempting to use the script argument with the remote-exec terraform Provisioner. According to the documentation, the script argument does the following:

script - This is a path (relative or absolute) to a local script that will be copied to the remote resource and then executed. This cannot be provided with inline or scripts.

Here is a link to the doc: https://www.terraform.io/docs/language/resources/provisioners/remote-exec.html

Here is the code:

    script = [
    "./scripts/provision.sh"
    ]

Here is the error:

Error: Incorrect attribute value type

on main.tf line 86, in resource "vsphere_virtual_machine" "vm":
86:    script = [
87:      "./scripts/provision.sh",
88:    ]

Inappropriate value for attribute "script": string required.

Any help would be appreciated.

3 Answers 3

5

I am new to TF - script does not take a list, which is defined by using [ ] square brackets. The solution is to use

script = "./scripts/provision.sh"
Sign up to request clarification or add additional context in comments.

Comments

3

If you look at the doc it says:

You cannot pass any arguments to scripts using the script or scripts arguments to this provisioner. If you want to specify arguments, upload the script with the file provisioner and then use inline to call it. Example:

resource "aws_instance" "web" {
  # ...

  provisioner "file" {
    source      = "script.sh"
    destination = "/tmp/script.sh"
  }

  provisioner "remote-exec" {
    inline = [
      "chmod +x /tmp/script.sh",
      "/tmp/script.sh args",
    ]
  }
}

Also, I would recommend using inline over script/scripts(my personal preference). If you need to use scripts use without braces.

Let me know if you need more help with remote exec.

Comments

0

in order to use array you have to use scripts option

 scripts = [
        "./scripts/provision.sh"
        ]

or

script = "./scripts/provision.sh"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.