github.com/hugorut/terraform@v1.1.3/website/docs/cli/commands/apply.mdx (about) 1 --- 2 page_title: 'Command: apply' 3 description: >- 4 The terraform apply command executes the actions proposed in a Terraform plan 5 to create, update, or destroy infrastructure. 6 --- 7 8 # Command: apply 9 10 > **Hands-on:** Try the [Terraform: Get Started](https://learn.hashicorp.com/collections/terraform/aws-get-started?utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) collection on HashiCorp Learn. 11 12 The `terraform apply` command executes the actions proposed in a Terraform 13 plan. 14 15 The most straightforward way to use `terraform apply` is to run it without 16 any arguments at all, in which case it will automatically create a new 17 execution plan (as if you had run `terraform plan`) and then prompt you to 18 approve that plan, before taking the indicated actions. 19 20 Another way to use `terraform apply` is to pass it the filename of a saved 21 plan file you created earlier with `terraform plan -out=...`, in which case 22 Terraform will apply the changes in the plan without any confirmation prompt. 23 This two-step workflow is primarily intended for when 24 [running Terraform in automation](https://learn.hashicorp.com/tutorials/terraform/automate-terraform?in=terraform/automation&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS). 25 26 ## Usage 27 28 Usage: `terraform apply [options] [plan file]` 29 30 The behavior of `terraform apply` differs significantly depending on whether 31 you pass it the filename of a previously-saved plan file. 32 33 ### Automatic Plan Mode 34 35 In the default case, with no saved plan file, `terraform apply` creates its own 36 plan of action, in the same way that [`terraform plan`](/cli/commands/plan) would. 37 38 Terraform will propose the plan to you and prompt you to approve it before 39 taking the described actions, unless you waive that prompt by using the 40 `-auto-approve` option. 41 42 When performing its own plan, `terraform apply` supports all of the same 43 [planning modes](/cli/commands/plan#planning-modes) and 44 [planning options](/cli/commands/plan#planning-options) that `terraform plan` would 45 accept, so you can customize how Terraform will create the plan. 46 47 ### Saved Plan Mode 48 49 If you pass the filename of a previously-saved plan file, `terraform apply` 50 performs exactly the steps specified by that plan file. It does not prompt for 51 approval; if you want to inspect a plan file before applying it, you can use 52 [`terraform show`](/cli/commands/show). 53 54 When using a saved plan, none of the planning modes or planning options linked 55 above are supported; these options only affect Terraform's decisions about which 56 actions to take, and the plan file contains the final results of those 57 decisions. 58 59 ### Plan Options 60 61 When run without a saved plan file, `terraform apply` supports all of `terraform 62 plan`'s planning modes and planning options. For details, see: 63 64 * [Planning Modes](/cli/commands/plan#planning-modes) 65 * [Planning Options](/cli/commands/plan#planning-options) 66 67 ### Apply Options 68 69 The following options allow you to change various details about how the 70 apply command executes and reports on the apply operation. If you are running 71 `terraform apply` _without_ a previously-saved plan file, these options are 72 _in addition to_ the planning modes and planning options described for 73 [`terraform plan`](/cli/commands/plan). 74 75 * `-auto-approve` - Skips interactive approval of plan before applying. This 76 option is ignored when you pass a previously-saved plan file, because 77 Terraform considers you passing the plan file as the approval and so 78 will never prompt in that case. 79 80 * `-compact-warnings` - Shows any warning messages in a compact form which 81 includes only the summary messages, unless the warnings are accompanied by 82 at least one error and thus the warning text might be useful context for 83 the errors. 84 85 * `-input=false` - Disables all of Terraform's interactive prompts. Note that 86 this also prevents Terraform from prompting for interactive approval of a 87 plan, so Terraform will conservatively assume that you do not wish to 88 apply the plan, causing the operation to fail. If you wish to run Terraform 89 in a non-interactive context, see 90 [Running Terraform in Automation](https://learn.hashicorp.com/tutorials/terraform/automate-terraform?in=terraform/automation&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS) for some 91 different approaches. 92 93 * `-json` - Enables the [machine readable JSON UI][machine-readable-ui] output. 94 This implies `-input=false`, so the configuration must have no unassigned 95 variable values to continue. To enable this flag, you must also either enable 96 the `-auto-approve` flag or specify a previously-saved plan. 97 98 [machine-readable-ui]: /internals/machine-readable-ui 99 100 * `-lock=false` - Don't hold a state lock during the operation. This is 101 dangerous if others might concurrently run commands against the same 102 workspace. 103 104 * `-lock-timeout=DURATION` - Unless locking is disabled with `-lock=false`, 105 instructs Terraform to retry acquiring a lock for a period of time before 106 returning an error. The duration syntax is a number followed by a time 107 unit letter, such as "3s" for three seconds. 108 109 * `-no-color` - Disables terminal formatting sequences in the output. Use this 110 if you are running Terraform in a context where its output will be 111 rendered by a system that cannot interpret terminal formatting. 112 113 * `-parallelism=n` - Limit the number of concurrent operation as Terraform 114 [walks the graph](/internals/graph#walking-the-graph). Defaults to 115 10\. 116 117 For configurations using 118 [the `local` backend](/language/settings/backends/local) only, 119 `terraform apply` also accepts the legacy options 120 [`-state`, `-state-out`, and `-backup`](/language/settings/backends/local#command-line-arguments). 121 122 ## Passing a Different Configuration Directory 123 124 Terraform v0.13 and earlier also accepted a directory path in place of the 125 plan file argument to `terraform apply`, in which case Terraform would use 126 that directory as the root module instead of the current working directory. 127 128 That usage was deprecated in Terraform v0.14 and removed in Terraform v0.15. 129 If your workflow relies on overriding the root module directory, use 130 [the `-chdir` global option](/cli/commands/#switching-working-directory-with-chdir) 131 instead, which works across all commands and makes Terraform consistently look 132 in the given directory for all files it would normally read or write in the 133 current working directory. 134 135 If your previous use of this legacy pattern was also relying on Terraform 136 writing the `.terraform` subdirectory into the current working directory even 137 though the root module directory was overridden, use 138 [the `TF_DATA_DIR` environment variable](/cli/config/environment-variables#tf_data_dir) 139 to direct Terraform to write the `.terraform` directory to a location other 140 than the current working directory.