github.com/hugorut/terraform@v1.1.3/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  -> **Note:** Provisioners should only be used as a last resort. For most
    21  common situations there are better alternatives. For more information, see
    22  [the main Provisioners page](/language/resources/provisioners).
    23  
    24  ## Example usage
    25  
    26  ```hcl
    27  resource "aws_instance" "web" {
    28    # ...
    29  
    30    # Establishes connection to be used by all 
    31    # generic remote provisioners (i.e. file/remote-exec)
    32    connection {
    33      type     = "ssh"
    34      user     = "root"
    35      password = var.root_password
    36      host     = self.public_ip
    37    }
    38  
    39    provisioner "remote-exec" {
    40      inline = [
    41        "puppet apply",
    42        "consul join ${aws_instance.web.private_ip}",
    43      ]
    44    }
    45  }
    46  ```
    47  
    48  ## Argument Reference
    49  
    50  The following arguments are supported:
    51  
    52  * `inline` - This is a list of command strings. They are executed in the order
    53    they are provided. This cannot be provided with `script` or `scripts`.
    54  
    55  * `script` - This is a path (relative or absolute) to a local script that will
    56    be copied to the remote resource and then executed. This cannot be provided
    57    with `inline` or `scripts`.
    58  
    59  * `scripts` - This is a list of paths (relative or absolute) to local scripts
    60    that will be copied to the remote resource and then executed. They are executed
    61    in the order they are provided. This cannot be provided with `inline` or `script`.
    62  
    63  -> **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.
    64  
    65  ## Script Arguments
    66  
    67  You cannot pass any arguments to scripts using the `script` or
    68  `scripts` arguments to this provisioner. If you want to specify arguments,
    69  upload the script with the
    70  [file provisioner](/language/resources/provisioners/file)
    71  and then use `inline` to call it. Example:
    72  
    73  ```hcl
    74  resource "aws_instance" "web" {
    75    # ...
    76  
    77    provisioner "file" {
    78      source      = "script.sh"
    79      destination = "/tmp/script.sh"
    80    }
    81  
    82    provisioner "remote-exec" {
    83      inline = [
    84        "chmod +x /tmp/script.sh",
    85        "/tmp/script.sh args",
    86      ]
    87    }
    88  }
    89  ```