terraform
state
ai_generated
true
Error: A resource with the ID already exists
ID: terraform/resource-already-exists
91%Fix Rate
93%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 115 | active | — | — | — |
| 1 | active | — | — | — |
Root Cause
Terraform tries to create a resource that already exists outside of its state.
genericWorkarounds
-
95% success Import the existing resource: terraform import <resource_addr> <resource_id>
Brings the existing resource under Terraform management
Sources: https://developer.hashicorp.com/terraform/cli/commands/import
-
90% success Use import blocks (Terraform 1.5+) for declarative import
import { to = aws_instance.web; id = 'i-12345' }
Dead Ends
Common approaches that don't work:
-
Deleting the existing resource manually
70% fail
May cause downtime; the resource may be in use by other systems
-
Changing the resource name in Terraform to avoid the conflict
75% fail
Creates a duplicate resource instead of managing the existing one