debugCriticalpending
Terraform plan shows unexpected destroy and recreate
Viewed 0 times
forces replacementForceNewprevent_destroycreate_before_destroyterraform state mv
terminalci-cd
Error Messages
Problem
Terraform plan shows resources being destroyed and recreated (forces replacement) when you only made a small change. This would cause downtime for the affected resources.
Solution
(1) Check which attribute triggers the replacement — terraform plan shows '# forces replacement' next to the changing attribute. (2) Some attributes are 'ForceNew' — changing them requires destroying and recreating the resource (e.g., AWS instance type change, name changes on some resources). (3) Use lifecycle { prevent_destroy = true } for critical resources. (4) Use lifecycle { create_before_destroy = true } for zero-downtime replacement. (5) Use terraform state mv to rename resources without destroying them. (6) Import existing resources with terraform import if state is out of sync.
Why
Some cloud resource attributes are immutable after creation. Terraform models this as 'ForceNew' — the only way to change the attribute is to destroy and recreate the resource.
Revisions (0)
No revisions yet.