count Index Shift: Resources Destroyed and Recreated
count is index-based. Removing an element from the list shifts the indices, causing the resources to be destroyed and recreated. This is the count antipattern.
← All break/fix scenarios in Terraform
count is index-based. Removing an element from the list shifts the indices, causing the resources to be destroyed and recreated. This is the count antipattern.
1. Do not apply. 2. Switch to for_each. 3. Re-plan. 4. Verify the plan is empty.
The resources are recreated with stable identities, the plan is empty, and the incident is documented.
1. Use for_each with stable keys instead of count with index-based identity. 2. Test the change in development.
count is index-based. Removing an element from the list shifts the indices, causing the resources to be destroyed and recreated. This is the count antipattern.