Deterministic topo sort (Kahn). Sorted ready-set so plans/applies
are reproducible (testable, reviewable) — the same determinism
discipline as the rest of the book.
State as the diff baseline. Plan diffs desired vs last-applied, not
desired vs live — matching real tools (and why drift, a separate
state-vs-live check, exists).
Deletes in reverse order. Dependencies must be torn down children-
first; computing this from the graph avoids orphan/ordering errors.
Attr-map equality for change detection. Minimal but real: a changed
attribute yields an Update with a human-readable diff.
State is the crown jewel and the biggest hazard. Lost/stale/corrupt
state makes the engine plan destructive nonsense. Production needs
remote state + locking + backups + import; this lab keeps state
in-memory to expose the mechanics.
Plan/apply is not transactional. A partial apply (some resources
created, then a failure) leaves a mixed world; real tools record
partial state and continue/retry. Model this as an exercise.
Drift correction can be destructive. Auto-reverting drift (pa-08
self-heal) overwrites a human's emergency fix; sometimes you want
alert-not-revert. An operational policy choice.
Ordering is from declared deps only. Implicit dependencies (a
resource referencing another's output) must be made explicit or the
graph is wrong — a real Terraform footgun.
Providers (real cloud APIs), modules, variables/outputs, remote state +
locking, partial-apply recovery, import, and plan as a reviewed CI
artifact gating apply (GitOps, pa-08).