github.com/hs0210/hashicorp-terraform@v0.11.12-beta1/website/docs/provisioners/local-exec.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Provisioner: local-exec"
     4  sidebar_current: "docs-provisioners-local"
     5  description: |-
     6    The `local-exec` provisioner invokes a local executable after a resource is created. This invokes a process on the machine running Terraform, not on the resource. See the `remote-exec` provisioner to run commands on the resource.
     7  ---
     8  
     9  # local-exec Provisioner
    10  
    11  The `local-exec` provisioner invokes a local executable after a resource is
    12  created. This invokes a process on the machine running Terraform, not on the
    13  resource. See the `remote-exec`
    14  [provisioner](/docs/provisioners/remote-exec.html) to run commands on the
    15  resource.
    16  
    17  Note that even though the resource will be fully created when the provisioner is
    18  run, there is no guarantee that it will be in an operable state - for example
    19  system services such as `sshd` may not be started yet on compute resources.
    20  
    21  ## Example usage
    22  
    23  ```hcl
    24  resource "aws_instance" "web" {
    25    # ...
    26  
    27    provisioner "local-exec" {
    28      command = "echo ${aws_instance.web.private_ip} >> private_ips.txt"
    29    }
    30  }
    31  ```
    32  
    33  ## Argument Reference
    34  
    35  The following arguments are supported:
    36  
    37  * `command` - (Required) This is the command to execute. It can be provided
    38    as a relative path to the current working directory or as an absolute path.
    39    It is evaluated in a shell, and can use environment variables or Terraform
    40    variables.
    41  
    42  * `working_dir` - (Optional) If provided, specifies the working directory where
    43    `command` will be executed. It can be provided as as a relative path to the
    44     current working directory or as an absolute path. The directory must exist.
    45  
    46  * `interpreter` - (Optional) If provided, this is a list of interpreter
    47    arguments used to execute the command. The first argument is the
    48    interpreter itself. It can be provided as a relative path to the current
    49    working directory or as an absolute path.  The remaining arguments are
    50    appended prior to the command.  This allows building command lines of the
    51    form "/bin/bash", "-c", "echo foo". If `interpreter` is unspecified,
    52    sensible defaults will be chosen based on the system OS.
    53  
    54  * `environment` - (Optional) block of key value pairs representing the
    55    environment of the executed command. inherits the current process environment.
    56  
    57  ### Interpreter Examples
    58  
    59  ```hcl
    60  resource "null_resource" "example1" {
    61    provisioner "local-exec" {
    62      command = "open WFH, '>completed.txt' and print WFH scalar localtime"
    63      interpreter = ["perl", "-e"]
    64    }
    65  }
    66  ```
    67  
    68  ```hcl
    69  resource "null_resource" "example2" {
    70    provisioner "local-exec" {
    71      command = "Get-Date > completed.txt"
    72      interpreter = ["PowerShell", "-Command"]
    73    }
    74  }
    75  ```
    76  
    77  ```hcl
    78  resource "aws_instance" "web" {
    79    # ...
    80  
    81    provisioner "local-exec" {
    82      command = "echo $FOO $BAR $BAZ >> env_vars.txt"
    83  
    84      environment {
    85        FOO = "bar"
    86        BAR = 1
    87        BAZ = "true"
    88      }
    89    }
    90  }
    91  ```