terraform
state_error
ai_generated
true
Error: Resource already managed by Terraform or import ID not found
ID: terraform/tf-import-resource-exists
85%Fix Rate
87%Confidence
75Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Terraform import failed because the resource already exists in state or the import ID format is incorrect.
genericWorkarounds
-
88% success Use terraform state rm to remove stale state entry before re-importing
terraform state rm MODULE.RESOURCE_ADDRESS, then terraform import MODULE.RESOURCE_ADDRESS RESOURCE_ID
Sources: https://developer.hashicorp.com/terraform/cli/commands/state/rm
-
85% success Use the import block in Terraform 1.5+ for declarative imports
Add import { to = RESOURCE_ADDRESS; id = "RESOURCE_ID" } block and run terraform planSources: https://developer.hashicorp.com/terraform/language/import
Dead Ends
Common approaches that don't work:
-
Delete the real resource and recreate it with Terraform
85% fail
Deleting production resources causes downtime; import exists specifically to avoid this
-
Force-push a new state file to overwrite the existing resource entry
80% fail
Overwriting state can cause other resources to become orphaned or duplicated
Error Chain
Preceded by:
Frequently confused with: