» Command: apply
For a hands-on tutorial, try the Get Started track on HashiCorp Learn.
terraform apply command is used to apply the changes required
to reach the desired state of the configuration, or the pre-determined
set of actions generated by a
terraform plan execution plan.
terraform apply [options] [dir-or-plan]
apply scans the current directory for the configuration
and applies the changes appropriately. However, a path to another configuration
or an execution plan can be provided. Explicit execution plan files can be
used to split plan and apply into separate steps within
If no explicit plan file is given on the command line,
terraform apply will
create a new plan automatically and prompt for approval to apply it. If the
created plan does not include any changes to resources or to root module
output values then
terraform apply will exit immediately, without prompting.
The command-line flags are all optional. The list of available flags are:
-backup=path- Path to the backup file. Defaults to
-state-outwith the ".backup" extension. Disabled by setting to "-".
-compact-warnings- If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.
-lock=true- Lock the state file when locking is supported.
-lock-timeout=0s- Duration to retry a state lock.
-input=true- Ask for input for variables if not directly set.
-auto-approve- Skip interactive approval of plan before applying.
-no-color- Disables output with coloring.
-refresh=true- Update the state for each resource prior to planning and applying. This has no effect if a plan file is given directly to apply.
-state=path- Path to the state file. Defaults to "terraform.tfstate". Ignored when remote state is used. This setting does not persist and other commands, such as init, may not be aware of the alternate statefile. To configure an alternate statefile path which is available to all terraform commands, use the local backend.
-var-file=foo- Set variables in the Terraform configuration from a variable file. If a
.auto.tfvarsfiles are present in the current directory, they will be automatically loaded.
terraform.tfvarsis loaded first and the
.auto.tfvarsfiles after in alphabetical order. Any files specified by
-var-fileoverride any values set automatically from files in the working directory. This flag can be used multiple times.