A teammate edited the state JSON to change a resource ID, pushed it, and now refresh fails for that resource with a provider error.
AdvancedTroubleshootingImport, Already Exists and State Surgery
Answer
Likely causes → Only id was changed; other attributes (ARN, nested IDs) still reference the old object, or schema_version / private provider data no longer match, so the provider can't read it.
Diagnose → terraform state show <addr>; compare id with arn and other identifiers.
Fix → Remove and re-import cleanly:
terraform state rm aws_lb.main
terraform import aws_lb.main arn:aws:elasticloadbalancing:ap-south-1:111122223333:loadbalancer/app/prod/abc123
Prevent → No manual state edits; reviewers should reject PRs or runbooks that suggest them.
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