github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/resources/provisioners/remote-exec.html.md (about)

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