`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.
More on Import, Already Exists and State Surgery
Apply fails with `EntityAlreadyExists: Role with name app-role already exists.`Beginner`terraform apply` on a new bucket fails with `BucketAlreadyExists`. You have never created that bucket.Beginner`Error: Resource already managed by Terraform` when running `terraform import aws_s3_bucket.logs acme-logs`.Beginner`Error: Cannot import non-existent remote object` for a resource you can see in the console.Intermediate`Error: Configuration for import target does not exist` when running `terraform plan` with an `import` block.Beginner`terraform plan -generate-config-out=generated.tf` fails with `Conflicting configuration arguments` in the generated file.Intermediate