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

After `terraform state mv aws_instance.web module.app.aws_instance.web`, the plan wants to destroy the instance and create a new one.

IntermediateTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → The destination address doesn't match the code (module is called module.application, or the resource uses count so it needs [0]); the state now has the object at an address the code doesn't declare.

Diagnose → terraform state list | grep aws_instance vs the code address shown in the plan's + create.

Fix → Move again to the exact address in the plan:

terraform state mv 'module.app.aws_instance.web' 'module.application.aws_instance.web[0]'

Prevent → Prefer moved blocks; terraform plan shows has moved to and you see mistakes before state changes.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery