One change to a VPC output makes the plan replace 30 resources. How do you find out why, and reduce the damage?
AdvancedScenarioImport Refactoring Drift and Lifecycle
Answer
Situation read → A cascading replacement through dependencies.
What I'd do →
- Read the plan top-down: find the first resource marked
forces replacement. - Trace the attribute that forced it with
terraform graph | dot -Tsvg. - Revert or restructure: avoid changing immutable inputs, or use
create_before_destroy. - Do not apply until the root cause is understood.
Why → Replacing a parent (subnet, VPC, role) forces replacement of everything that has it as an immutable argument.
Interview tip → A blast-radius estimate in the PR description shows maturity.
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