Terraform import fails with "already exists": the ID is wrong or it is already managed
Import errors about objects already existing mean the remote ID you gave maps to something Terraform already tracks, or the provider found a duplicate. Teaches ID verification before import. Not for different error messages.
TL;DR: Import errors about objects already existing mean the remote ID you gave maps to something Terraform already tracks, or the provider found a duplicate. Teaches ID verification before import. Check whether the target address is already in state: terraform state list | grep [name]. If the address exists, you do not need to import; you need to reconcile config with the existing object.
The error
Error: ... already existsWhat you are seeing
Variants include provider errors like Error: ... already exists, InvalidParameterValue: ... already exists, or Terraform refusing because the target address is already in state. You ran an import (block or CLI) and the provider says the thing is already there.
First response
- Check whether the target address is already in state:
terraform state list | grep [name]. If the address exists, you do not need to import; you need to reconcile config with the existing object. - Verify the import ID format against the provider docs. Import IDs are provider-specific and often not the obvious identifier: AWS security groups want
sg-xxx, but some resources wantname/vpc-idcomposites. A wrong ID can resolve to an existing different object. - For
importblocks: Terraform 1.5+ plans the import before applying it. Runterraform planfirst; the plan shows exactly what will be imported and flags conflicts before anything changes. - If the provider reports the remote object already exists under a different Terraform address, someone imported it before. Find the existing address with
terraform state listand either use it orterraform state mvthe old address away first.
Rules for agents
- Never import into an address that already has state. Remove or move the old state entry first, deliberately.
- Import does not generate config by itself (unless you use
-generate-config-out, which writes a starting-point file you must review). An import without matching config just creates perpetual diffs. - After a successful import, the next plan must be clean or explainable. If it wants to destroy/recreate, the config does not match reality; fix the config, not the state.
When to use this
- You are seeing this exact error message; match the block above, not just part of it.
- The failing call matches the scenario in the title: Terraform import fails with "already exists".
- You want the fastest verified fix before digging through logs.
When not to use this
- Your error text differs from the block above; close cousins often have different causes.
- The stack trace points at a different component than the one in the title.
- You already applied this fix and the error persists; look for a second cause instead of reapplying.
Compatibility
- Mentions 1.5 in the original; behavior may differ on much older or newer releases.
Also seen as
InvalidParameterValue: ... already exists
Edge cases
- Import does not generate config by itself (unless you use -generate-config-out, which writes a starting-point file you must review).