The index trap
Resources created with count are tracked by position. Resources created with for_each are tracked by name. Remove one item from the middle and see what Terraform would do.
1. Pick how the resources are created
2. Edit the list
Click × to remove an item, or add a new one. The first two table columns below show what Terraform stored last time.
3. What Terraform would do
| State key before | Storage account before | Action | State key after |
|---|
How to get out of it
If you already used count, you can switch to for_each without destroying anything by adding moved blocks that map each old index to its new key, then confirming the plan shows moves only. The full walkthrough is in the article and in Refactoring Terraform State Without Destroying Everything.
This lab is a simplified model: the storage account name changes with the list entry, and a changed name forces a replacement (destroy, then create).