INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

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.

What you will learn

Distinguish configuration, state and current resources, then explain what to review before applying and verifying a plan.

Prerequisite

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

Three things to distinguish before planning
NameJobIn this example
ConfigurationDescribes the resources and values you want to manage.The intended allowed port is 443.
StateRecords mappings to real objects and attributes that were read.Which rule is managed and previously recorded values.
Current resourcesObjects 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

Read the change workflow
Read the change workflow1: Edit configuration — Create a plan — Review a plan. 2: Review a plan — Review impact — Apply operations. 3: Apply operations — Inspect results — Verify outcomes123Edit configurationReview a planApply operationsVerify outcomesRead the change workflow1: Edit configuration — Create a plan — Review a plan. 2: Review a plan — Review impact — Apply operations. 3: Apply operations — Inspect results — Verify outcomes123EditconfigurationReview a planApplyoperationsVerify outcomes
  1. Edit configuration → Review a planCreate a plan
  2. Review a plan → Apply operationsReview impact
  3. 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

Read one setting by time and role
What you inspectFixed valueWhat it establishes
Earlier state record80A previous observation, not proof that the value stayed 80.
Current target read8080There is a difference from that record; investigate its reason.
Configuration443The intended value, not necessarily an applied one.
Proposed change8080 → 443A 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

The apply input determines the planning and confirmation flow
Operation formMeaningReview point
Inspect a planPreview proposed changes.Targets or configuration can change later.
Apply without a saved planCreate a new plan, normally request confirmation, then apply.The new plan is not necessarily the earlier preview.
Apply a saved planExecute 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

Fixed example: the second of two changes fails
StageFixed outcomeWhat to inspect next
Change ACompleted.Its actual state and the recorded result.
Change BFailed because permission was missing.The error and the remaining change scope.
Overall operationEnded with an error.Do not assume change A was automatically reversed.
  1. Read errors and completed operations, then inspect resources and state.
  2. Preserve ownership and intent while correcting the cause, such as permissions or inputs.
  3. 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.

A plan proposes 8080→443. Has traffic already succeeded on 443?
Read the answer and reason

Answer: No; inspect execution and test communication separately · It is a proposal, not evidence of execution or application availability.

An earlier state record says 80; the current read says 8080. What should you check first?
Read the answer and reason

Answer: Check the reason and ownership before deciding intent · It may be a necessary incident fix; do not overwrite a difference without understanding it.

Apply is run without a saved plan. Must it execute the earlier preview unchanged?
Read the answer and reason

Answer: No; inspect the newly generated plan · Review the current plan and its target and input conditions.

Does applying a saved plan always show an approval prompt before execution?
Read the answer and reason

Answer: No; review the plan and target before passing it · Saved-plan mode does not prompt for approval; review beforehand.

A completed and B failed. Does the overall error mean A was automatically reverted?
Read the answer and reason

Answer: No; inspect completed changes and actual resources · Completed changes can remain; an overall error is not proof of rollback.

A value is redacted in plan output. Does that prove no secret is stored?
Read the answer and reason

Answer: No; inspect persistence and control access · Values can remain in state or saved plans despite display redaction.

Does remote state always guarantee locking regardless of backend?
Read the answer and reason

Answer: No; check backend support and configuration · Verify support and manage concurrent operations accordingly.

Check, then explain in your own words

  1. Distinguish the three roles in the table.
  2. Explain the fixed 80/8080/443 example by observation time.
  3. 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.