github.com/cycloidio/terraform@v1.1.10-0.20220513142504-76d5c768dc63/website/docs/language/resources/provisioners/remote-exec.mdx (about) 1 --- 2 page_title: 'Provisioner: remote-exec' 3 description: >- 4 The `remote-exec` provisioner invokes a script on a remote resource after it 5 is created. This can be used to run a configuration management tool, bootstrap 6 into a cluster, etc. To invoke a local process, see the `local-exec` 7 provisioner instead. The `remote-exec` provisioner supports both `ssh` and 8 `winrm` type connections. 9 --- 10 11 # remote-exec Provisioner 12 13 The `remote-exec` provisioner invokes a script on a remote resource after it 14 is created. This can be used to run a configuration management tool, bootstrap 15 into a cluster, etc. To invoke a local process, see the `local-exec` 16 [provisioner](/language/resources/provisioners/local-exec) instead. The `remote-exec` 17 provisioner requires a [connection](/language/resources/provisioners/connection) 18 and supports both `ssh` and `winrm`. 19 20 ~> **Important:** Use provisioners as a last resort. There are better alternatives for most situations. Refer to 21 [Declaring Provisioners](/language/resources/provisioners/syntax) for more details. 22 23 ## Example usage 24 25 ```hcl 26 resource "aws_instance" "web" { 27 # ... 28 29 # Establishes connection to be used by all 30 # generic remote provisioners (i.e. file/remote-exec) 31 connection { 32 type = "ssh" 33 user = "root" 34 password = var.root_password 35 host = self.public_ip 36 } 37 38 provisioner "remote-exec" { 39 inline = [ 40 "puppet apply", 41 "consul join ${aws_instance.web.private_ip}", 42 ] 43 } 44 } 45 ``` 46 47 ## Argument Reference 48 49 The following arguments are supported: 50 51 * `inline` - This is a list of command strings. They are executed in the order 52 they are provided. This cannot be provided with `script` or `scripts`. 53 54 * `script` - This is a path (relative or absolute) to a local script that will 55 be copied to the remote resource and then executed. This cannot be provided 56 with `inline` or `scripts`. 57 58 * `scripts` - This is a list of paths (relative or absolute) to local scripts 59 that will be copied to the remote resource and then executed. They are executed 60 in the order they are provided. This cannot be provided with `inline` or `script`. 61 62 -> **Note:** Since `inline` is implemented by concatenating commands into a script, [`on_failure`](/language/resources/provisioners/syntax#failure-behavior) applies only to the final command in the list. In particular, with `on_failure = fail` (the default behaviour) earlier commands will be allowed to fail, and later commands will also execute. If this behaviour is not desired, consider using `"set -o errexit"` as the first command. 63 64 ## Script Arguments 65 66 You cannot pass any arguments to scripts using the `script` or 67 `scripts` arguments to this provisioner. If you want to specify arguments, 68 upload the script with the 69 [file provisioner](/language/resources/provisioners/file) 70 and then use `inline` to call it. Example: 71 72 ```hcl 73 resource "aws_instance" "web" { 74 # ... 75 76 provisioner "file" { 77 source = "script.sh" 78 destination = "/tmp/script.sh" 79 } 80 81 provisioner "remote-exec" { 82 inline = [ 83 "chmod +x /tmp/script.sh", 84 "/tmp/script.sh args", 85 ] 86 } 87 } 88 ```