Skip to main content

Module 2: Infrastructure as Code: Worked Examples

Example 1: Review a Destructive Plan

A plan replaces a database because an immutable name changed. Do not approve from the summary alone. Inspect resource address, replacement cause, data lifecycle, backup/restore evidence, dependency order, downtime, and rollback. Add lifecycle protection only with an explicit removal procedure; it is a guardrail, not a recovery plan.

Example 2: Recover State Safely

When remote state is locked, first identify the active owner and backend health. Never force-unlock while an apply may still run. Preserve state history, reconcile actual resources with plan/import/move operations, and require a peer-reviewed recovery record.

Example 3: Design a Module Boundary

A useful network module exposes intent—CIDRs, zones, endpoint needs—and returns stable identifiers. It does not expose every provider argument or silently create unrelated databases and clusters. Version behavior, validate inputs, and test examples.

Completion Standard

  • Review plans for replacement, privilege, cost, and drift.
  • Rehearse state recovery without creating duplicate resources.
  • Build one small composable module with tests and upgrade notes.