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

You imported a resource into the default workspace instead of `staging`. Now default has a stray object.

IntermediateTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → Forgot terraform workspace select staging before importing.

Diagnose → terraform workspace list, then terraform state list in each.

Fix → In default: terraform state rm <addr> (only forgets, doesn't delete). In staging: import it again.

Prevent → Use separate directories/backends per environment instead of workspaces for long-lived envs, or a wrapper that requires an explicit ENV= argument.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery