← 返回命令列表

Linux command

terraform-apply 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Apply changes

terraform apply

Apply a saved plan

terraform apply [plan.tfplan]

Apply without confirmation

terraform apply -auto-approve

Apply with a variable

terraform apply -var="[key]=[value]"

Replace a specific resource

terraform apply -replace=[resource]

Apply with limited parallelism

terraform apply -parallelism=[n]

说明

terraform apply executes the actions proposed in a Terraform plan to create, update, or destroy infrastructure. When run without a saved plan file, it automatically creates a new plan, prompts for approval, and then performs the proposed changes. When given a saved plan file (from terraform plan -out), it executes the plan without prompting. The command compares the desired state defined in configuration files against the current state and determines the minimal set of changes needed. It supports all planning modes and options from terraform plan when no saved plan is provided.

参数

-auto-approve
Skip interactive approval of the plan before applying.
-var _name=value_
Set an input variable value. Can be specified multiple times.
-var-file _file_
Load variable values from a file.
-replace _resource_
Force replacement of a specific resource instance.
-target _resource_
Limit the operation to a specific resource and its dependencies.
-parallelism _n_
Limit the number of concurrent operations. Default is 10.
-compact-warnings
Show warning messages in compact form with only the summary.
-input _true|false_
Enable or disable interactive prompts. Default is true.
-lock _true|false_
Lock the state file during operations. Default is true.
-lock-timeout _duration_
Duration to retry acquiring a state lock. Default is 0s.
-no-color
Disable color codes in the output.
-json
Enable machine-readable JSON output. Implies -input=false.
-destroy
Create a plan to destroy all resources, then apply it.
-refresh-only
Only update the state to match remote objects.
-state _path_
Path to the state file (legacy, local backend only).
-backup _path_
Path to backup the previous state file.

FAQ

What is the terraform-apply command used for?

terraform apply executes the actions proposed in a Terraform plan to create, update, or destroy infrastructure. When run without a saved plan file, it automatically creates a new plan, prompts for approval, and then performs the proposed changes. When given a saved plan file (from terraform plan -out), it executes the plan without prompting. The command compares the desired state defined in configuration files against the current state and determines the minimal set of changes needed. It supports all planning modes and options from terraform plan when no saved plan is provided.

How do I run a basic terraform-apply example?

Run `terraform apply` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -auto-approve do in terraform-apply?

Skip interactive approval of the plan before applying.