Interview Prep/Terraform/Workflow and Providers

A scheduled job should alert when infrastructure differs from code, without changing anything. What do you use?

IntermediateScenarioWorkflow and Providers
Answer

Situation read → You want a read-only drift check with machine-readable results.

What I'd do →

  1. Run terraform plan -detailed-exitcode -lock=false -input=false on a schedule with a read-only role.
  2. Exit code 0 means no change, 1 means error, 2 means changes pending.
  3. On 2, post the plan summary to Slack or open a ticket.
terraform plan -detailed-exitcode -input=false -lock=false
case $? in 2) echo "DRIFT";; 1) echo "ERROR"; exit 1;; esac

Why → The exit code makes drift detection scriptable without parsing text.

Interview tip → Note that pending code changes also produce exit 2, so run drift jobs against the main branch only.

All Terraform questions Roadmap: Terraform

More on Workflow and Providers