Synopsis
Show changes required by the current configurationDescription
Theterraform plan command generates a speculative execution plan, showing what actions Terraform would take to apply the current configuration. This command will not actually perform the planned actions.
You can optionally save the plan to a file, which you can then pass to the terraform apply command to perform exactly the actions described in the plan.
Usage
Options
Plan Customization
The following options customize how Terraform will produce its plan. You can also use these options when you runterraform apply without passing it a saved plan, in order to plan and apply in a single command.
Select the “destroy” planning mode, which creates a plan to destroy all objects currently managed by this Terraform configuration instead of the usual behavior.
Select the “refresh only” planning mode, which checks whether remote objects still match the outcome of the most recent Terraform apply but does not propose any actions to undo any changes made outside of Terraform.
Skip checking for external changes to remote objects while creating the plan. This can potentially make planning faster, but at the expense of possibly planning against a stale record of the remote system state.
Force replacement of a particular resource instance using its resource address. If the plan would’ve normally produced an update or no-op action for this instance, Terraform will plan to replace it instead. You can use this option multiple times to replace more than one object.
Limit the planning operation to only the given module, resource, or resource instance and all of its dependencies. You can use this option multiple times to include more than one object. 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.Output Options
If Terraform produces any warnings that are not accompanied by errors, shows them in a more compact form that includes only the summary messages.
Return detailed exit codes when the command exits. This will change the meaning of exit codes to:
- 0 = Succeeded, diff is empty (no changes)
- 1 = Errored
- 2 = Succeeded, there is a diff
Write a plan file to the given path. This can be used as input to the
terraform apply command.Produce output in a machine-readable JSON format.
If specified, output won’t contain any color.
Generation Options
(Experimental) If import blocks are present in configuration, instructs Terraform to generate HCL for any imported resources not already present. The configuration is written to a new file at the specified path, which must not already exist. Terraform may still attempt to write configuration if the plan errors.
State Management
Ask for input for variables if not directly set.
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.
Limit the number of concurrent operations.
A legacy option used for the local backend only. See the local backend’s documentation for more information.
Examples
Basic Plan
Generate an execution plan:Save Plan to File
Save the execution plan to a file:Destroy Plan
Create a plan to destroy all resources:Target Specific Resources
Plan changes for specific resources only:Force Replacement
Force replacement of a specific resource:Set Variables
Plan with variable values:Detailed Exit Codes
Use detailed exit codes (useful for CI/CD):Exit Codes
Default Mode
0- Success1- Error occurred
With -detailed-exitcode
0- Succeeded, diff is empty (no changes)1- Error occurred2- Succeeded, there is a diff (changes present)