Topic lessonTopic: Terraform: change workflow and sensitive data
Terraform plan, apply and state: understanding the change workflow
A plan proposes changes, apply performs planned operations, and state records how configuration maps to managed objects. “Change to 443 is proposed” and “the service works on 443” are different claims. Follow one edit while distinguishing files, records, current resources and execution results.
Distinguish configuration, state and current resources, then explain what to review before applying and verifying a plan.
A basic understanding of infrastructure as code helps. CDK knowledge and an AWS account are unnecessary. Read fixed examples here; this page does not run Terraform.
Separate configuration, records and current resources
| Name | Job | In this example |
|---|---|---|
| Configuration | Describes the resources and values you want to manage. | The intended allowed port is 443. |
| State | Records mappings to real objects and attributes that were read. | Which rule is managed and previously recorded values. |
| Current resources | Objects inspected through the target service, such as its API. | The port currently allowed by that rule. |
State is not a live dashboard. Someone may change a resource after it was recorded. Normal planning reads the target and compares it with configuration to propose changes. Do not equate an earlier record with a value just observed.
Read the plan, decide, apply, then verify behavior
- Edit configuration → Review a planCreate a plan
- Review a plan → Apply operationsReview impact
- Apply operations → Verify outcomesInspect results
- Edit configuration
- Intended values and scope
- Review a plan
- Proposed adds, changes, deletes
- Apply operations
- Target and reviewed operations
- Verify outcomes
- Resources, traffic, application
The arrows show work, not network traffic. Displaying a plan does not apply its proposed changes. After apply completes, verify the communication and application functions you use. The existence of state does not prove those functions work.
Fixed example: recorded 80, observed 8080, intended 443
| What you inspect | Fixed value | What it establishes |
|---|---|---|
| Earlier state record | 80 | A previous observation, not proof that the value stayed 80. |
| Current target read | 8080 | There is a difference from that record; investigate its reason. |
| Configuration | 443 | The intended value, not necessarily an applied one. |
| Proposed change | 8080 → 443 | A proposal towards configuration, not a successful traffic test. |
The change to 8080 may have been needed during an incident. Check its reason and ownership before deciding whether to revise configuration or change the object. A value in code is not, by itself, a reason to immediately overwrite a necessary fix.
Distinguish a preview from a saved plan
| Operation form | Meaning | Review point |
|---|---|---|
| Inspect a plan | Preview proposed changes. | Targets or configuration can change later. |
| Apply without a saved plan | Create a new plan, normally request confirmation, then apply. | The new plan is not necessarily the earlier preview. |
| Apply a saved plan | Execute operations in that saved plan. | No interactive approval prompt; review the artifact and target before passing it. |
When using a saved plan, keep the reviewed artifact matched to the one passed for execution. Saving it neither guarantees successful application nor prevents every external change. Review the target, inputs, configuration revision, state conditions and execution permissions together.
After an apply error, do not assume nothing changed
| Stage | Fixed outcome | What to inspect next |
|---|---|---|
| Change A | Completed. | Its actual state and the recorded result. |
| Change B | Failed because permission was missing. | The error and the remaining change scope. |
| Overall operation | Ended with an error. | Do not assume change A was automatically reversed. |
- Read errors and completed operations, then inspect resources and state.
- Preserve ownership and intent while correcting the cause, such as permissions or inputs.
- Review a new plan and decide on remaining changes and recovery conditions.
Teams need shared state and a way to avoid concurrent writes. State locking depends on backend support. Remote storage is not a blanket safety guarantee: inspect encryption, access and locking separately.
Check planning, application and records with fixed cases
Choose an option to see the result and explanation.
Check, then explain in your own words
- Distinguish the three roles in the table.
- Explain the fixed 80/8080/443 example by observation time.
- Check saved-plan and partial-failure cases, then explain pre- and post-apply verification.
Check your understanding: Someone says “the plan has been reviewed.” What should you check before and after apply?
Check the target, configuration, inputs, reviewed plan, apply mode and impact. Afterwards inspect completed and failed operations, state, actual objects and the functions you use.
An earlier preview, state, execution results and application behavior are different evidence.
Sources and conditions checked
The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.
- Purpose of Terraform StateChecked:
Scope and conditionsResource mappings and recorded attributes; state is not continuous monitoring or a data restore point.
Used in this lessonSeparate configuration, records and current resources Read the plan, decide, apply, then verify behavior Fixed example: recorded 80, observed 8080, intended 443 After an apply error, do not assume nothing changed Check planning, application and records with fixed cases
- Create a Terraform planChecked:
Scope and conditionsPlanning workflow involving configuration, state and current resources; documentation review, not local CLI or AWS execution.
Used in this lessonSeparate configuration, records and current resources Fixed example: recorded 80, observed 8080, intended 443
- Terraform plan commandChecked:
Scope and conditionsNormal planning reads targets and proposes changes; distinguish a proposal from an applied outcome.
Used in this lessonSeparate configuration, records and current resources Read the plan, decide, apply, then verify behavior Fixed example: recorded 80, observed 8080, intended 443 Distinguish a preview from a saved plan Check planning, application and records with fixed cases
- Terraform apply commandChecked:
Scope and conditionsReplanning without a saved plan, no approval prompt in saved-plan mode, and no automatic rollback of partially completed operations.
Used in this lessonRead the plan, decide, apply, then verify behavior Distinguish a preview from a saved plan After an apply error, do not assume nothing changed Check planning, application and records with fixed cases
Scope and conditionsRedaction differs from persistence; inspect state/plan handling and separate ephemeral and write-only conditions.
Used in this lessonDistinguish a preview from a saved plan After an apply error, do not assume nothing changed Check planning, application and records with fixed cases
- Terraform state lockingChecked:
Scope and conditionsLocking depends on backend support; remote storage alone does not guarantee it, and force-unlock is not a routine fix.
Used in this lessonAfter an apply error, do not assume nothing changed Check planning, application and records with fixed cases