The Terraform plan output is a crucial component of the core Terraform workflow that shows you what changes Terraform will make to your infrastructure before actually applying them. Understanding this output helps you verify intended changes and catch potential issues early.
When you run 'terrafor…The Terraform plan output is a crucial component of the core Terraform workflow that shows you what changes Terraform will make to your infrastructure before actually applying them. Understanding this output helps you verify intended changes and catch potential issues early.
When you run 'terraform plan', Terraform compares your current configuration files against the existing state and displays a detailed execution plan. The output uses specific symbols to indicate different types of changes:
+ (plus sign in green): Indicates a resource will be created
- (minus sign in red): Indicates a resource will be destroyed
~ (tilde in yellow): Indicates a resource will be modified in-place
-/+ : Indicates a resource will be destroyed and recreated (replacement)
The plan output shows each affected resource with its full address, including the resource type and name. For each resource, you'll see the attributes that will change, with the current value shown alongside the new value.
Key sections of the plan output include:
1. Resource actions summary: Lists all resources and their planned actions
2. Attribute changes: Shows specific attribute modifications with before and after values
3. Plan summary: Displays total counts of resources to add, change, or destroy
Some attributes may show '(known after apply)' which means the value will only be determined during the apply phase, typically for computed values like resource IDs or IP addresses.
The plan also highlights sensitive values, marking them as 'sensitive value' to protect confidential data from being displayed in logs.
Best practices include always reviewing the plan output carefully before applying changes, especially looking for unexpected destroys or replacements. You can save the plan to a file using 'terraform plan -out=planfile' for later execution, ensuring the exact reviewed changes are applied.
Understanding Plan Output in Terraform
Why Understanding Plan Output is Important
The terraform plan output is one of the most critical aspects of using Terraform safely and effectively. It serves as your preview window into what changes Terraform will make to your infrastructure before any actual modifications occur. Mastering the ability to read and interpret plan output is essential for:
• Preventing unintended changes - Catching destructive operations before they happen • Validating infrastructure changes - Ensuring the expected resources are being created, modified, or removed • Collaboration and review - Enabling team members to review proposed changes • Compliance and auditing - Documenting what changes were planned before execution
What is Plan Output?
When you run terraform plan, Terraform compares your current configuration files against the existing state file and determines what actions are necessary to achieve the desired state. The plan output is a detailed report showing:
• Resources to be created (shown with a + symbol) • Resources to be destroyed (shown with a - symbol) • Resources to be modified in-place (shown with a ~ symbol) • Resources to be replaced (shown with -/+ symbols)
How Plan Output Works
The plan output is structured to provide maximum clarity:
1. Resource Address - Shows the full path to the resource (e.g., aws_instance.web_server)
2. Action Symbols: • + create - A new resource will be added • - destroy - An existing resource will be removed • ~ update in-place - Resource will be modified but not recreated • -/+ destroy and recreate - Resource must be replaced due to force-new changes • +/- create before destroy - New resource created first, then old one removed
3. Attribute Changes - Each attribute that will change is listed with its current and new values
4. Known vs Unknown Values - Values marked as (known after apply) indicate computed attributes that will only be determined after the resource is created
5. Summary Line - At the bottom, a summary shows the total count of resources to add, change, or destroy
Reading Attribute Changes
Within each resource block, you will see attribute changes formatted as:
• attribute_name = "old_value" -> "new_value" for modifications • + attribute_name = "value" for new attributes • - attribute_name = "value" for removed attributes
Some attributes may show (forces replacement) indicating that changing this attribute requires destroying and recreating the entire resource.
Exam Tips: Answering Questions on Understanding Plan Output
1. Memorize the symbols - Know what +, -, ~, -/+, and +/- mean. Questions frequently test whether you can identify what action will occur based on the symbol shown.
2. Understand force replacement triggers - Be aware that certain attribute changes require resource replacement rather than in-place updates. Look for (forces replacement) annotations.
3. Pay attention to the summary line - Questions may ask how many resources will be affected. The summary at the bottom of plan output provides these counts.
4. Know the difference between update and replace - In-place updates (~) modify existing resources, while replacements (-/+) destroy and recreate them. This distinction is commonly tested.
5. Recognize computed values - When you see (known after apply), understand this means Terraform cannot determine the value until the resource exists.
6. Understand plan file usage - The -out flag saves a plan to a file that can be applied later. This ensures the exact planned changes are executed.
7. Resource addressing format - Be familiar with how resources are addressed in output: resource_type.resource_name or module.module_name.resource_type.resource_name
8. No changes scenario - When infrastructure matches configuration, plan shows No changes. Infrastructure is up-to-date.
9. Practice reading sample outputs - The exam may present plan output snippets and ask you to interpret them. Being comfortable with the format saves valuable time.