teluzia.Cloud Engineer · Day 156
CHAPTER 23 · FLAGSHIP CAPSTONE

Terraform infrastructure implementation

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

What you’re learning today

Terraform implementation is today's starting point. A plan showing '-/+' for a database indicates replacement, not an in-place update. Read the replacement reason and data-preservation strategy before apply; format and validation alone cannot detect that operational risk. You will connect this with state and secrets and change lifecycle. The lesson's artifact brings these decisions together: Draft provider, variables and outputs for the capstone, then create a paper plan listing additions and one risky replacement without applying cloud resources.

Think of it this way

Terraform configuration is the blueprint, state is the address book of built objects, and the plan is the proposed change order.

TOPIC 01 / 03Step by step

Terraform implementation

Write resources and variables around the agreed architecture. Format and validate configuration, then review a plan; a syntactically valid file can still create an unsafe public resource. A plan showing '-/+' for a database indicates replacement, not an in-place update. Read the replacement reason and data-preservation strategy before apply; format and validation alone cannot detect that operational risk.

WORKED EXAMPLE
A plan showing '-/+' for a database indicates replacement, not an in-place update. Read the replacement reason and data-preservation strategy before apply; format and validation alone cannot detect that operational risk.

A resource address identifies a managed object in configuration/state; a plan compares desired and observed state; replacement recreates rather than updates an object. Imagine a network change proposes replacing the compute service and its attached resource. Review dependency ordering, interruption and data persistence before accepting the plan. Variable values can change the result, so record the environment-specific inputs without exposing secrets. Terraform validation checks configuration structure, not whether the chosen architecture meets every security or availability requirement. A reusable module reduces repeated declarations but can hide significant changes behind an input. Inspect the actual planned resources and reason about their request-path impact. Apply only in an authorized sandbox and verify outputs against the application and pipeline contract, not merely against a successful command exit.

Why this matters

Read the replacement reason and data-preservation strategy before apply; format and validation alone cannot detect that operational risk.

A common trap

A valid Terraform configuration cannot propose an unsafe resource.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Terraform implementation

Write resources and variables around the agreed architecture. Format and validate configuration, then review a plan; a syntactically valid file can still create an unsafe public resource. A plan showing '-/+' for a database indicates replacement, not an in-place update. Read the replacement reason and data-preservation strategy before apply; format and validation alone cannot detect that operational risk.

WORKED EXAMPLE
A plan showing '-/+' for a database indicates replacement, not an in-place update. Read the replacement reason and data-preservation strategy before apply; format and validation alone cannot detect that operational risk.

A resource address identifies a managed object in configuration/state; a plan compares desired and observed state; replacement recreates rather than updates an object. Imagine a network change proposes replacing the compute service and its attached resource. Review dependency ordering, interruption and data persistence before accepting the plan. Variable values can change the result, so record the environment-specific inputs without exposing secrets. Terraform validation checks configuration structure, not whether the chosen architecture meets every security or availability requirement. A reusable module reduces repeated declarations but can hide significant changes behind an input. Inspect the actual planned resources and reason about their request-path impact. Apply only in an authorized sandbox and verify outputs against the application and pipeline contract, not merely against a successful command exit.

Why this matters

Read the replacement reason and data-preservation strategy before apply; format and validation alone cannot detect that operational risk.

A common trap

A valid Terraform configuration cannot propose an unsafe resource.

State and secrets

State records resource bindings and may contain sensitive values. Use protected storage and appropriate locking; do not publish state files or assume marking a variable sensitive removes it from state. An output can be hidden as sensitive while its underlying value remains in state. Restrict backend access, use locking where supported and avoid committing state or publishing raw outputs.

WORKED EXAMPLE
An output can be hidden as sensitive while its underlying value remains in state. Restrict backend access, use locking where supported and avoid committing state or publishing raw outputs.

State binds resource addresses to real identifiers; locking coordinates concurrent writers where supported; sensitive marking controls presentation rather than removing underlying values. Imagine two operators apply from different local state copies. Both may believe they own the same names, creating conflict or unmanaged resources. Use the intended backend and coordination method, and keep state access limited to authorized automation and operators. Review whether generated passwords or outputs are stored in the state before sharing it. Backup and recovery of state are operational concerns distinct from application data backup. Centralized state improves collaboration but becomes a sensitive dependency requiring availability and access controls. When a mismatch occurs, investigate bindings and actual resources before editing or deleting state, because removing a binding does not remove the corresponding cloud object.

Why this matters

Restrict backend access, use locking where supported and avoid committing state or publishing raw outputs.

A common trap

Sensitive variables never appear in state.

Change lifecycle

Plan shows intended changes, while apply executes an approved plan in a real environment. Review replacements and dependencies; cleanup should use the same state and verify residual resources. Plan from the intended state, review proposed creates/changes/deletes, then apply only in an authorized sandbox. Destroy through the same resource bindings and verify storage, snapshots or retained items separately.

WORKED EXAMPLE
Plan from the intended state, review proposed creates/changes/deletes, then apply only in an authorized sandbox. Destroy through the same resource bindings and verify storage, snapshots or retained items separately.

Initialization prepares providers/modules/backend; planning proposes changes; application executes selected changes. Imagine the app release needs a new environment setting while infrastructure renames a service. Coordinate the outputs and pipeline target so a successful apply does not leave CI deploying to the old name. Review creates, updates and deletes as a release decision and document any dependency on manual configuration. Teardown must use the intended bindings and account, and may leave intentionally retained resources or snapshots requiring separate review. Automation makes repetition easier but can repeat unsafe intent quickly. Keep the plan, execution evidence and post-change request validation connected to one commit, and define how to recover a partial failure instead of assuming a failed apply rolled back everything automatically. Inventory remaining objects after cleanup.

Why this matters

Destroy through the same resource bindings and verify storage, snapshots or retained items separately.

A common trap

Deleting state proves remote cloud resources were removed.

KEEP THESE WITH YOU

Today’s takeaways

Terraform implementation: Write resources and variables around the agreed architecture.

State and secrets: State records resource bindings and may contain sensitive values.

Change lifecycle: Plan shows intended changes, while apply executes an approved plan in a real environment.

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