How do you find out that someone changed infrastructure outside Terraform?
BeginnerScenarioImport Refactoring Drift and Lifecycle
Answer
Situation read → Console hotfix; code and reality have diverged.
What I'd do →
- Run
terraform plan; drifted attributes appear as changes to revert. - Use
terraform plan -refresh-onlyto see only drift with no code changes mixed in. - Automate a scheduled plan that alerts on exit code 2.
Why → Refresh reads real attributes from the cloud API and compares with state and code.
Interview tip → Drift detection is only useful if somebody owns the alert.
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.IntermediateSomeone opened port 22 on a security group in the console. Terraform wants to remove it. What's your process?IntermediateAn 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