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:
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.
2 Answers
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" 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.