Someone opened port 22 on a security group in the console. Terraform wants to remove it. What's your process?
IntermediateScenarioImport Refactoring Drift and Lifecycle
Answer
Situation read → Revert or codify? Find out why it happened first.
What I'd do →
- Ask who changed it and why; check CloudTrail (
AuthorizeSecurityGroupIngress). - If it was an unauthorised or temporary change, run
terraform applyto revert. - If it's a legitimate need, add it to code through a PR, then apply.
Why → Terraform's job is to enforce the desired state, but humans decide what that state should be.
Interview tip → Mention follow-up: restrict console write access so drift becomes rare.
More on Import Refactoring Drift and Lifecycle
An S3 bucket was created by hand in the console and now must be managed by Terraform. How do you bring it in?BeginnerYou must adopt 200 existing resources and don't want to write all the HCL by hand.IntermediateHow do you find out that someone changed infrastructure outside Terraform?BeginnerAn Auto Scaling group's desired capacity is changed by autoscaling, and Terraform keeps resetting it.IntermediateHow do you protect a production database from an accidental `terraform destroy`?BeginnerA load balancer's TLS certificate must be rotated with no outage.Intermediate