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 →
- Run
terraform plan -detailed-exitcode -lock=false -input=falseon a schedule with a read-only role. - Exit code
0means no change,1means error,2means changes pending. - 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.
More on Workflow and Providers
A new teammate is about to run Terraform for the first time against a shared dev account. Which commands do you walk them through, and in what order?BeginnerYour manager asks why we bother with `terraform plan` when `apply` shows the same diff before asking for confirmation. What do you say?BeginnerTwo engineers get different provider versions and see different plans for the same code. How do you stop this?BeginnerSomeone committed the `.terraform/` directory to the repo. What should be in version control and what should not?BeginnerThe same configuration must create a VPC in `us-east-1` and a DR copy of a bucket in `eu-west-1`. How do you do it with one root module?IntermediateYou must deploy the same stack into 12 AWS accounts. How do you handle credentials and provider configuration?Intermediate