github.com/pulumi/terraform@v1.4.0/website/docs/language/resources/provisioners/local-exec.mdx (about) 1 --- 2 page_title: 'Provisioner: local-exec' 3 description: >- 4 The `local-exec` provisioner invokes a local executable after a resource is 5 created. This invokes a process on the machine running Terraform, not on the 6 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](/language/resources/provisioners/remote-exec) 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 ~> **Important:** Use provisioners as a last resort. There are better alternatives for most situations. Refer to 22 [Declaring Provisioners](/language/resources/provisioners/syntax) for more details. 23 24 ## Example usage 25 26 ```hcl 27 resource "aws_instance" "web" { 28 # ... 29 30 provisioner "local-exec" { 31 command = "echo ${self.private_ip} >> private_ips.txt" 32 } 33 } 34 ``` 35 36 ## Argument Reference 37 38 The following arguments are supported: 39 40 * `command` - (Required) This is the command to execute. It can be provided 41 as a relative path to the current working directory or as an absolute path. 42 It is evaluated in a shell, and can use environment variables or Terraform 43 variables. 44 45 * `working_dir` - (Optional) If provided, specifies the working directory where 46 `command` will be executed. It can be provided as a relative path to the 47 current working directory or as an absolute path. The directory must exist. 48 49 * `interpreter` - (Optional) If provided, this is a list of interpreter 50 arguments used to execute the command. The first argument is the 51 interpreter itself. It can be provided as a relative path to the current 52 working directory or as an absolute path. The remaining arguments are 53 appended prior to the command. This allows building command lines of the 54 form "/bin/bash", "-c", "echo foo". If `interpreter` is unspecified, 55 sensible defaults will be chosen based on the system OS. 56 57 * `environment` - (Optional) block of key value pairs representing the 58 environment of the executed command. inherits the current process environment. 59 60 * `when` - (Optional) If provided, specifies when Terraform will execute the command. 61 For example, `when = destroy` specifies that the provisioner will run when the associated resource 62 is destroyed. Refer to [Destroy-Time Provisioners](/language/resources/provisioners/syntax#destroy-time-provisioners) 63 for details. 64 65 * `quiet` - (Optional) If set to `true`, Terraform will not print the command to be executed to stdout, and will instead print "Suppressed by quiet=true". Note that the output of the command will still be printed in any case. 66 67 ### Interpreter Examples 68 69 ```hcl 70 resource "terraform_data" "example1" { 71 provisioner "local-exec" { 72 command = "open WFH, '>completed.txt' and print WFH scalar localtime" 73 interpreter = ["perl", "-e"] 74 } 75 } 76 ``` 77 78 ```hcl 79 resource "terraform_data" "example2" { 80 provisioner "local-exec" { 81 command = "Get-Date > completed.txt" 82 interpreter = ["PowerShell", "-Command"] 83 } 84 } 85 ``` 86 87 ```hcl 88 resource "aws_instance" "web" { 89 # ... 90 91 provisioner "local-exec" { 92 command = "echo $FOO $BAR $BAZ >> env_vars.txt" 93 94 environment = { 95 FOO = "bar" 96 BAR = 1 97 BAZ = "true" 98 } 99 } 100 } 101 ```