How do you test a refactor so that you're sure nothing will be destroyed?
IntermediateScenarioImport Refactoring Drift and Lifecycle
Answer
Situation read → A refactor should have a no-op plan.
What I'd do →
- Run
terraform plan -out=refactor.tfplanagainst a copy of production state or a staging replica. - Inspect with
terraform show -json refactor.tfplan | jq '.resource_changes[] | select(.change.actions != ["no-op"]) | .address'. - Gate the PR on that command printing only intended moves.
Why → The plan is machine-readable truth about what will change.
Interview tip → Moves show as no-op with previous_address set.
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?BeginnerSomeone 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`?Beginner