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

You ran `terraform state rm aws_db_instance.main` to "fix" a plan error. The next apply fails with `DBInstanceAlreadyExists`.

IntermediateTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → state rm only forgets the object; the database still exists. The code still declares it, so Terraform tries to create a new one with the same identifier.

Diagnose → aws rds describe-db-instances --db-instance-identifier prod-db

Fix → Re-import it:

terraform import aws_db_instance.main prod-db
terraform plan

Prevent → Use state rm only when you also remove the block (or use a removed block, which does both in one reviewed change).

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery