Deployment & Infra
Infrastructure as Code: multiple-choice review
Six questions that cut across the whole unit. Each one mirrors a judgment call you make at a terminal during a real change window — not a definition to recite, but a tradeoff to weigh while production is watching.
Confirm you can connect declarative desired state, the plan/apply diff engine, the role of the state file, locking under concurrency, and drift handling — the synthesis the lesson built toward.
Your config declares an S3 bucket. You run apply once, then run apply again with no change to the config and no out-of-band change. What should happen on the second apply, and which property guarantees it?
A teammate asks: 'Why keep a state file at all? Just refresh against the live cloud every time and diff that.' What is the strongest reason the state file is not optional?
Two CI jobs both run `terraform apply` against the same backend nine seconds apart, with locking disabled via `-lock=false`. What is the core failure mode?
A CI run crashed mid-apply and left a stale lock. The next pipeline fails fast with `Error acquiring the state lock`. A junior wants to run `terraform force-unlock` immediately and re-apply. What is the senior caution?
During a 2am incident a teammate hand-edited a security-group rule in the console to stop the bleeding. Nobody touched the code. A routine `terraform apply` runs Tuesday morning. What is the danger, and what should have happened first?
A generated database password ends up as a Terraform output, and the state file lives in an S3 bucket several engineers can read. What is the exposure, and what is the right pattern?
The through-line: you declare desired state, plan diffs it against the recorded state file (refreshing the provider first), and apply executes the diff idempotently. The state file is the identity map — source of truth and hazard at once: keep it in a versioned, locked remote backend, never route secrets through it, and confront drift deliberately with plan -refresh-only, deciding intent before an apply silently reverts an emergency fix. Lean toward immutable infrastructure so there is less to drift in the first place.