Someone changed a security group in prod through the console during an incident. How do you detect and handle this kind of drift?
IntermediateScenarioMulti-env and multi-account
Answer
Situation read → Manual changes during incidents are sometimes necessary. The problem is when they're forgotten, then overwritten by the next apply, or left as hidden config.
What I'd do →
- Detect: a scheduled
terraform plan -detailed-exitcodein CI for each stack (exit code 2 means drift), posting to Slack.
terraform plan -detailed-exitcode -lock=false -out=drift.tfplan; echo "exit=$?"
- Real-time detection: EventBridge rule on console-originated CloudTrail write events in prod.
- Decide per drift: if the manual change was right, codify it in Terraform; if not, apply to revert.
- Process: incidents allow manual changes, but the postmortem includes "codify or revert" as a tracked action.
Why → Drift that's detected the same day is easy; drift found six months later during an apply causes outages.
Interview tip → Mention -detailed-exitcode; it's how you make drift detection scriptable.
More on Multi-env and multi-account
Design the AWS account structure for a 50-engineer startup that's growing fast.IntermediateHow do you promote the same build from dev to staging to prod?BeginnerBugs keep passing staging and appearing in production. How do you make staging closer to prod?IntermediateHow do you structure Terraform for dev, staging and prod? Workspaces, directories or Terragrunt?IntermediateDevelopers want a preview environment for every pull request. How would you build it?AdvancedHelm values files or Kustomize overlays for per-environment config?Beginner