Synopsis
Create or update infrastructureDescription
Theterraform apply command creates or updates infrastructure according to Terraform configuration files in the current directory.
By default, Terraform will generate a new plan and present it for your approval before taking any action. You can optionally provide a plan file created by a previous call to terraform plan, in which case Terraform will take the actions described in that plan without any confirmation prompt.
Usage
Arguments
Optional path to a saved plan file created by
terraform plan -out=FILE. If provided, Terraform will apply exactly the changes described in that plan without generating a new plan or prompting for approval.Options
Approval Options
Skip interactive approval of plan before applying.
Ask for input for variables if not directly set.
Plan Mode Options
If you don’t provide a saved plan file, this command also accepts all of the plan-customization options fromterraform plan:
Destroy Terraform-managed infrastructure. The command
terraform destroy is a convenience alias for this option.Select the “refresh only” mode, which only updates the state to match remote objects without proposing any changes.
Update the state prior to checking for differences. Set to false to skip refreshing.
Force replacement of a particular resource instance using its resource address. Terraform will plan to replace this resource instance instead of updating it. Can be used multiple times.
Limit the apply operation to only the given module, resource, or resource instance and all of its dependencies. Can be used multiple times. This is for exceptional use only.
Variable Options
Set a value for one of the input variables in the root module of the configuration. Use this option more than once to set more than one variable. Format:
-var 'name=value'Load variable values from the given file, in addition to the default files
terraform.tfvars and *.auto.tfvars. Use this option more than once to include more than one variables file.State Management
Don’t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.
Duration to retry a state lock. For example: ”10s” for 10 seconds.
Path to read and save state (unless state-out is specified). Defaults to “terraform.tfstate”. Legacy option for the local backend only.
Path to write state to that is different than “-state”. This can be used to preserve the old state. Legacy option for the local backend only.
Path to backup the existing state file before modifying. Defaults to the “-state-out” path with “.backup” extension. Set to ”-” to disable backup.
Performance Options
Limit the number of parallel resource operations.
Output Options
If Terraform produces any warnings that are not accompanied by errors, show them in a more compact form that includes only the summary messages.
Produce output in a machine-readable JSON format. When using this flag with a plan file argument, you must also specify
-auto-approve.If specified, output won’t contain any color.
Examples
Basic Apply
Apply changes with interactive approval:Auto-Approve
Apply changes without interactive approval:Apply Saved Plan
Apply a saved plan file:Apply with Variables
Apply with variable values:Target Specific Resources
Apply changes to specific resources only:Force Replacement
Force replacement of a resource:Apply with Outputs
Example showing outputs after apply:Exit Codes
0- Success1- Error occurred