How to fix Error: Duplicate import for ID - The same resource cannot be imported twice in Terraform

TerraformINTERMEDIATEMEDIUMUpdated Dec 30, 2025ยท 127 views

Terraform fails to import resources when the same import block ID is used multiple times. This error prevents Terraform from processing import configurations that reference different modules or resources with the same ID value.

Quick fix

Fixes Error: Duplicate import for ID - The same resource cannot be imported twice

grep -r "id = " . --include="*.tf" | grep -E "import|id"
  1. Identify all import blocks with duplicate IDs
  2. Make import IDs unique across different target resources
  3. Check Terraform version
  4. Use scoped resource IDs with module context
terraform โ€” error
grep -r "id = " . --include="*.tf" | grep -E "import|id"
Error: Duplicate import for ID - The same resource cannot be imported twice

What this error means

The Terraform import feature allows you to bring existing infrastructure under Terraform management by associating real resources with your configuration. When Terraform encounters multiple import blocks with the same ID value, it cannot determine which physical resource should be imported to which address in your configuration. This is detected during initialization (terraform init) before any import operations occur.

Typical symptoms

  • Terraform init fails during import validation phase
  • Error message shows the same ID appears in multiple import blocks
  • Both the problematic import and the previously declared import are listed in the error
  • Error occurs specifically during init, before terraform import commands are executed

Common causes

  1. Multiple import blocks reference the same resource ID across different module instances
  2. Copy-pasted import blocks not updated with unique IDs
  3. Using identical default IDs when importing into different modules
  4. Terraform treating resource IDs as global instead of per-resource-type

How to fix "Error: Duplicate import for ID - The same resource cannot be imported twice"

1Identify all import blocks with duplicate IDs

Search your configuration for import blocks using the same ID:

bash
grep -r "id = " . --include="*.tf" | grep -E "import|id"

Or use Terraform's built-in syntax validation:

bash
terraform validate

This will show you all import blocks and highlight which ones share the same ID.

2Make import IDs unique across different target resources

Update your import blocks to use unique IDs. Instead of:

hcl
import {
  id = "default"
  to = module.us-east-1.aws_ebs_encryption_by_default.default
}

import {
  id = "default"
  to = module.us-west-2.aws_ebs_encryption_by_default.default
}

Change to:

hcl
import {
  id = "default"
  to = module.us-east-1.aws_ebs_encryption_by_default.default
}

import {
  id = "default"
  to = module.us-west-2.aws_ebs_encryption_by_default.default
}

The key difference is in the to address - even if the ID is "default", Terraform should distinguish them by their full resource address in different modules.

3Check Terraform version

This issue was reported in Terraform's GitHub issue #33390 as a false-positive validation bug. Check your Terraform version:

bash
terraform version

If you're using an older version, upgrade to the latest:

bash
# macOS
brew upgrade terraform

# Linux
wget https://releases.hashicorp.com/terraform/<VERSION>/terraform_<VERSION>_linux_amd64.zip
unzip terraform_<VERSION>_linux_amd64.zip
sudo mv terraform /usr/local/bin/

Newer versions have fixes for this false-positive detection.

4Use scoped resource IDs with module context

If using child modules, ensure each import uses the complete resource address path:

hcl
import {
  id = "us-east-1:default"
  to = module.us-east-1.aws_ebs_encryption_by_default.default
}

import {
  id = "us-west-2:default"
  to = module.us-west-2.aws_ebs_encryption_by_default.default
}

This makes the ID unique while keeping it semantically clear which region/module it belongs to.

5Execute import operations separately

If you have multiple imports of the same resource type, consider importing them one at a time:

bash
terraform import module.us-east-1.aws_ebs_encryption_by_default.default default
terraform import module.us-west-2.aws_ebs_encryption_by_default.default default

This avoids having multiple import blocks with the same ID in your configuration file. After importing, remove the import blocks from your _auto_import.tf file.

6Verify configuration after fixing

Once you've updated the import blocks or IDs, validate your configuration:

bash
terraform init
terraform validate
terraform plan

The init should now succeed without duplicate ID errors, and plan will show you what Terraform intends to import.

Advanced notes

This error is often a false-positive validation bug in earlier Terraform versions. The core issue is that Terraform's import validation logic compares import block IDs and resource types in isolation rather than considering the full resource address that includes module context.

Key distinctions:
- An import block ID is just an identifier for the import operation - it doesn't have to be globally unique across all imports
- The to address is what matters for uniqueness - it must point to distinct resources in your configuration
- When importing the same physical resource ID into different modules, the full address (module path + resource type + name) is what differentiates them

Future versions of Terraform may support truly global resource IDs across modules, but until then, ensure your import block IDs are contextually unique or structured to make it clear they target different modules.

Workaround for older versions: If upgrading Terraform isn't possible, you can:
1. Import resources one at a time via CLI
2. Store imports in separate .tf files per module
3. Use sequential naming (e.g., id1, id2) if semantic naming isn't critical

Frequently asked questions

What does "Error: Duplicate import for ID - The same resource cannot be imported" mean?
The Terraform import feature allows you to bring existing infrastructure under Terraform management by associating real resources with your configuration. When Terraform encounters multiple import blocks with the same ID value, it cannot determine which physical resource should be imported to which address in your configuration. This is detected during initialization (terraform init) before any import operations occur.
How do I fix "Error: Duplicate import for ID - The same resource cannot be imported"?
Terraform fails to import resources when the same import block ID is used multiple times. This error prevents Terraform from processing import configurations that reference different modules or resources with the same ID value.
What causes "Error: Duplicate import for ID - The same resource cannot be imported"?
Multiple import blocks reference the same resource ID across different module instances Copy-pasted import blocks not updated with unique IDs Using identical default IDs when importing into different modules
Is the "Error: Duplicate import for ID - The same resource cannot be imported" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading