Q&A-1Explain declarative IaC and where its convergence model stops.
Answer
The 90-second answer. Declarative IaC means you write the end state: three subnets, one RDS instance at 15.4, and the tool owns the how: read current state, diff against desired, build a dependency graph, apply in topological order. Terraform, CloudFormation, Pulumi and Kubernetes controllers all work this way. The convergence model stops in four places: partial application with no transaction, drift between runs, irreversible data side effects, and work that isn't a resource (data migrations, ordering against an app deploy).
Mechanism. Terraform's loop is refresh → plan → apply. Refresh calls each provider's read API and updates the state file; plan diffs that against config; apply walks the DAG, running up to -parallelism=10 operations concurrently by default. Kubernetes inverts the loop: a controller watches the API server and reconciles on every event, plus a periodic resync, so drift is corrected in seconds rather than at the next plan.
Where it stops.
No transaction. Terraform has no rollback. If resource 7 of 12 fails, the first 6 stay applied and state records them; you fix forward. CloudFormation does roll back the stack by default, but rollback can itself fail and leave DELETE_FAILED resources you clean up by hand. Kubernetes has no notion of a failed apply at all: it retries the reconcile indefinitely.
Drift. Terraform only sees out-of-band changes when you run plan or apply. Someone editing a security group in the console at 09:00 is invisible until the next run. Controllers see it immediately.
Irreversible effects. terraform destroy on an S3 bucket with objects fails unless force_destroy = true; a dropped Postgres column is gone. prevent_destroy and create_before_destroy are guardrails, not undo.
Non-resource work. Backfilling a column, reindexing, draining a node before a version bump: these are ordered against the infra change but aren't expressible as resources.
| Terraform | CloudFormation | K8s controller | |
|---|---|---|---|
| failure mid-apply | partial, fix forward | stack rollback (can fail) | retry forever |
| drift detection | on plan/apply | on drift detection (manual or scheduled) | continuous |
| undo a data change | none | none | none |
Trace. 12 resources, parallelism 10. The first wave starts 10. #7 fails on an IAM eventual-consistency error. Terraform waits for the other 9 in flight, marks #7 failed, and does not start #11 and #12, which depend on it. State now holds 9 resources. Re-run after fixing: refresh finds 9, plan proposes 3.
Alternatives. Ansible is ordered tasks, not a graph: good for procedural runbooks, poor for a 500-resource graph. CDK and Pulumi generate declarative templates from real code, which helps when you need loops and conditionals but doesn't change the convergence semantics.
When not to use it. One-off data migrations, per-request dynamic infrastructure, and brownfield resources you can't import. terraform import works, but you must hand-write matching config or the next plan destroys the resource.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.