github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/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 -> **Note:** Provisioners should only be used as a last resort. For most 22 common situations there are better alternatives. For more information, see 23 [the main Provisioners page](./). 24 25 ## Example usage 26 27 ```hcl 28 resource "aws_instance" "web" { 29 # ... 30 31 provisioner "local-exec" { 32 command = "echo ${aws_instance.web.private_ip} >> private_ips.txt" 33 } 34 } 35 ``` 36 37 ## Argument Reference 38 39 The following arguments are supported: 40 41 * `command` - (Required) This is the command to execute. It can be provided 42 as a relative path to the current working directory or as an absolute path. 43 It is evaluated in a shell, and can use environment variables or Terraform 44 variables. 45 46 * `working_dir` - (Optional) If provided, specifies the working directory where 47 `command` will be executed. It can be provided as as a relative path to the 48 current working directory or as an absolute path. The directory must exist. 49 50 * `interpreter` - (Optional) If provided, this is a list of interpreter 51 arguments used to execute the command. The first argument is the 52 interpreter itself. It can be provided as a relative path to the current 53 working directory or as an absolute path. The remaining arguments are 54 appended prior to the command. This allows building command lines of the 55 form "/bin/bash", "-c", "echo foo". If `interpreter` is unspecified, 56 sensible defaults will be chosen based on the system OS. 57 58 * `environment` - (Optional) block of key value pairs representing the 59 environment of the executed command. inherits the current process environment. 60 61 ### Interpreter Examples 62 63 ```hcl 64 resource "null_resource" "example1" { 65 provisioner "local-exec" { 66 command = "open WFH, '>completed.txt' and print WFH scalar localtime" 67 interpreter = ["perl", "-e"] 68 } 69 } 70 ``` 71 72 ```hcl 73 resource "null_resource" "example2" { 74 provisioner "local-exec" { 75 command = "Get-Date > completed.txt" 76 interpreter = ["PowerShell", "-Command"] 77 } 78 } 79 ``` 80 81 ```hcl 82 resource "aws_instance" "web" { 83 # ... 84 85 provisioner "local-exec" { 86 command = "echo $FOO $BAR $BAZ >> env_vars.txt" 87 88 environment = { 89 FOO = "bar" 90 BAR = 1 91 BAZ = "true" 92 } 93 } 94 } 95 ```