teluzia.Cloud Engineer · Day 96
CHAPTER 14 · ADVANCED TERRAFORM

Plan review, lifecycle and state safety

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Lifecycle rules are construction constraints; they can shape the work order but cannot make every planned change harmless. Review downstream effects alongside each resource action. Replacement can change IDs used by other components, and deleting an object may remove durable data. Plan review should identify the intended business outcome, operational window, account scope, and evidence needed after changes. create_before_destroy can reduce some replacement interruption but may require spare capacity or unique names. prevent_destroy blocks certain planned destruction while the configuration remains applicable. ignore_changes delegates selected drift handling; excessive use can hide configuration changes that matter for security or reliability.

Think of it this way

Lifecycle rules are construction constraints; they can shape the work order but cannot make every planned change harmless.

TOPIC 01 / 03Step by step

Plan review and dependencies

Review downstream effects alongside each resource action. Replacement can change IDs used by other components, and deleting an object may remove durable data. Plan review should identify the intended business outcome, operational window, account scope, and evidence needed after changes. For example, replacing a subnet can affect resources depending on its ID even when the subnet block appears to be the only edited text.

WORKED EXAMPLE
Replacing a subnet can affect resources depending on its ID even when the subnet block appears to be the only edited text.

A small source edit changes a network resource attribute requiring replacement. The plan then changes dependent IDs and perhaps recreates attached resources. Reviewing only the edited block misses the operational reach of the proposal. Trace resource actions and dependencies, then connect them to downtime, data, naming, and rollback requirements.

A dependency consumes another object's value or otherwise requires its behavior. Replacement exchanges one remote identity for another. Blast radius is the set of outcomes affected by failure or change. Plans explain proposed actions, but some runtime values and service constraints are only resolved later. Ask why each deletion exists and whether it belongs to the intended environment. A concise review record should state requirement, actions, dependencies, expected disruption, and validation. Large action counts are not automatically unsafe, nor small counts automatically safe: deleting one database can be more serious than updating many harmless metadata fields.

Why this matters

Replacing a subnet can affect resources depending on its ID even when the subnet block appears to be the only edited text.

A common trap

Do not overlook this operational distinction: Plan review should identify the intended business outcome, operational window, account scope, and evidence needed after changes.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Plan review and dependencies

Review downstream effects alongside each resource action. Replacement can change IDs used by other components, and deleting an object may remove durable data. Plan review should identify the intended business outcome, operational window, account scope, and evidence needed after changes. For example, replacing a subnet can affect resources depending on its ID even when the subnet block appears to be the only edited text.

WORKED EXAMPLE
Replacing a subnet can affect resources depending on its ID even when the subnet block appears to be the only edited text.

A small source edit changes a network resource attribute requiring replacement. The plan then changes dependent IDs and perhaps recreates attached resources. Reviewing only the edited block misses the operational reach of the proposal. Trace resource actions and dependencies, then connect them to downtime, data, naming, and rollback requirements.

A dependency consumes another object's value or otherwise requires its behavior. Replacement exchanges one remote identity for another. Blast radius is the set of outcomes affected by failure or change. Plans explain proposed actions, but some runtime values and service constraints are only resolved later. Ask why each deletion exists and whether it belongs to the intended environment. A concise review record should state requirement, actions, dependencies, expected disruption, and validation. Large action counts are not automatically unsafe, nor small counts automatically safe: deleting one database can be more serious than updating many harmless metadata fields.

Why this matters

Replacing a subnet can affect resources depending on its ID even when the subnet block appears to be the only edited text.

A common trap

Do not overlook this operational distinction: Plan review should identify the intended business outcome, operational window, account scope, and evidence needed after changes.

Lifecycle behavior

create_before_destroy can reduce some replacement interruption but may require spare capacity or unique names. prevent_destroy blocks certain planned destruction while the configuration remains applicable. ignore_changes delegates selected drift handling; excessive use can hide configuration changes that matter for security or reliability. For example, ignoring all security-group rule changes can hide unwanted access drift rather than fix the underlying ownership conflict.

WORKED EXAMPLE
Ignoring all security-group rule changes can hide unwanted access drift rather than fix the underlying ownership conflict.

A resource needs replacement. create_before_destroy may let Terraform create its replacement first, but the service could forbid duplicate names or lack spare quota. prevent_destroy can reject a planned destruction while its configuration protection applies. ignore_changes can leave selected externally managed attributes alone. Each option shapes behavior rather than guaranteeing a safe outcome.

Lifecycle is configuration controlling selected management decisions. Replacement ordering affects when old and new objects coexist. Ignoring drift delegates selected attributes to another source of truth. Choose these rules from real ownership and availability needs. Excessive ignore_changes can hide unwanted access changes; prevent_destroy is not a data backup and has limits if configuration is removed or management changes. Document constraints and test representative plans. A rule that blocks a legitimate maintenance procedure should trigger a design conversation, not automatic removal of every safeguard merely to make the next command succeed.

Why this matters

Ignoring all security-group rule changes can hide unwanted access drift rather than fix the underlying ownership conflict.

A common trap

Do not overlook this operational distinction: ignore_changes delegates selected drift handling; excessive use can hide configuration changes that matter for security or reliability.

Moves and state safety

Use moved blocks for supported address refactoring rather than destroy-and-recreate behavior caused by a rename. State commands are powerful operational tools and require backups, scope verification, and ownership reasoning. Do not edit state JSON manually as a routine shortcut or bypass a valid active lock. For example, a moved block maps terraform_data.old to terraform_data.new so a rename preserves the tracked object relationship.

WORKED EXAMPLE
A moved block maps terraform_data.old to terraform_data.new so a rename preserves the tracked object relationship.

A refactor renames aws_instance.worker to aws_instance.app without intending a new server. Terraform would otherwise see a removed address and a new address. A moved block declares that the old logical ownership should be associated with the new address, preserving the existing remote mapping where supported. Review the plan to verify the intended move rather than replacement.

An address is Terraform's logical identity. A moved declaration records an intentional refactor. A state operation changes management metadata and deserves careful scope verification. Preserve a secure backup and prevent concurrent writers before exceptional state maintenance. Do not manually edit serialized state because a JSON change looks simple; schema, dependencies, and provider metadata make unsupported edits risky. Moving state does not move a server's physical region or change business data. It changes how configuration refers to an owned object, and any actual infrastructure modification remains a separate reviewed operation.

Why this matters

A moved block maps terraform_data.old to terraform_data.new so a rename preserves the tracked object relationship.

A common trap

Do not overlook this operational distinction: Do not edit state JSON manually as a routine shortcut or bypass a valid active lock.

KEEP THESE WITH YOU

Today’s takeaways

Plan review and dependencies: Review downstream effects alongside each resource action. Replacement can change IDs used by other components, and deleting an object may remove durable data. Plan review should identify the intended business outcome, operational window, account scope, and evidence needed after changes.

Lifecycle behavior: create_before_destroy can reduce some replacement interruption but may require spare capacity or unique names. prevent_destroy blocks certain planned destruction while the configuration remains applicable. ignore_changes delegates selected drift handling; excessive use can hide configuration changes that matter for security or reliability.

Moves and state safety: Use moved blocks for supported address refactoring rather than destroy-and-recreate behavior caused by a rename. State commands are powerful operational tools and require backups, scope verification, and ownership reasoning. Do not edit state JSON manually as a routine shortcut or bypass a valid active lock.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed