github.com/pulumi/terraform@v1.4.0/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. The provisioner uses a default
    52    shell unless you specify a shell as the first command (eg., `#!/bin/bash`). 
    53    You cannot provide this 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  ```