Interview Prep/Terraform/Import, Already Exists and State Surgery

`terraform state mv` returns `Error: Invalid target address` when moving between `count` and `for_each` instances.

BeginnerTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → Missing quotes around string keys, or using [0] where the code now uses for_each keys.

Diagnose → terraform state list | grep aws_subnet

Fix →

terraform state mv 'aws_subnet.private[0]' 'aws_subnet.private["ap-south-1a"]'

Better: a moved block per instance, which can be reviewed in a plan.

Prevent → When converting count → for_each, generate moved blocks from a list in one PR.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery