- Adding a disk to one VM shifts downstream indices
- Reordering environment JSON changes flatten order
- Terraform treats shifted indices as new resources
- Attached to stateful application tiers
- Used for databases, middleware, or batch workloads
- Deployed across zones for resiliency
- Data loss
- Extended outages
- Failed change windows
- Deterministic
- Independent of ordering
- Human-readable
- Stable across environments
|
VM
|
LUN
|
Stable Key
|
|
vm1
|
0
|
vm1-0
|
|
vm1
|
1
|
vm1-1
|
|
vm2
|
0
|
vm2-0
|
- Inspects Terraform modules for index-based for_each
- Reads environment JSON files (such as ALZ variable abstractions)
- Reconstructs the exact flatten order used by Terraform
- Generates precise terraform state mv commands
- No guessing
- No manual address mapping
- No production surprises
- Discoverable
- Versioned
- Shareable across teams
terraform state mv \
'module.managed_disk_windowsvm_app["0"]' \
'module.managed_disk_windowsvm_app["vm1-0"]'
-
- terraform plan shows no pending changes
-
- Replace index-based keys with stable keys
-
- Especially critical with remote backends (Azure Storage)
-
- Only after terraform init is connected to the correct backend
-
- Existing disks should show no changes
-
- Terraform creates only the new disk
- Ensure the correct environment is initialized
- Run migrations once per environment
- Never merge stable-key code before migrating all environments
- Index-based for_each keys are unsafe for long-lived Azure disks
- Stable keys such as vm-lun eliminate accidental resource churn
- State migration is mandatory—not optional
- Copilot skills are powerful for institutionalizing safe patterns
- Small Terraform design choices can have enterprise-scale impact