github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/provisioners/remote-exec.html.markdown (about)

     1  ---
     2  layout: "docs"
     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/provisioners/local-exec.html) instead. The `remote-exec`
    15  provisioner supports both `ssh` and `winrm` type [connections](/docs/provisioners/connection.html).
    16  
    17  -> **Note:** Provisioners should only be used as a last resort. For most
    18  common situations there are better alternatives. For more information, see
    19  [the main Provisioners page](./).
    20  
    21  ## Example usage
    22  
    23  ```hcl
    24  resource "aws_instance" "web" {
    25    # ...
    26  
    27    provisioner "remote-exec" {
    28      inline = [
    29        "puppet apply",
    30        "consul join ${aws_instance.web.private_ip}",
    31      ]
    32    }
    33  }
    34  ```
    35  
    36  ## Argument Reference
    37  
    38  The following arguments are supported:
    39  
    40  * `inline` - This is a list of command strings. They are executed in the order
    41    they are provided. This cannot be provided with `script` or `scripts`.
    42  
    43  * `script` - This is a path (relative or absolute) to a local script that will
    44    be copied to the remote resource and then executed. This cannot be provided
    45    with `inline` or `scripts`.
    46  
    47  * `scripts` - This is a list of paths (relative or absolute) to local scripts
    48    that will be copied to the remote resource and then executed. They are executed
    49    in the order they are provided. This cannot be provided with `inline` or `script`.
    50  
    51  ## Script Arguments
    52  
    53  You cannot pass any arguments to scripts using the `script` or
    54  `scripts` arguments to this provisioner. If you want to specify arguments,
    55  upload the script with the
    56  [file provisioner](/docs/provisioners/file.html)
    57  and then use `inline` to call it. Example:
    58  
    59  ```hcl
    60  resource "aws_instance" "web" {
    61    # ...
    62  
    63    provisioner "file" {
    64      source      = "script.sh"
    65      destination = "/tmp/script.sh"
    66    }
    67  
    68    provisioner "remote-exec" {
    69      inline = [
    70        "chmod +x /tmp/script.sh",
    71        "/tmp/script.sh args",
    72      ]
    73    }
    74  }
    75  ```