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.
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.
Search your configuration for import blocks using the same ID:
grep -r "id = " . --include="*.tf" | grep -E "import|id"Or use Terraform's built-in syntax validation:
terraform validateThis will show you all import blocks and highlight which ones share the same ID.
Update your import blocks to use unique IDs. Instead of:
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:
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.
This issue was reported in Terraform's GitHub issue #33390 as a false-positive validation bug. Check your Terraform version:
terraform versionIf you're using an older version, upgrade to the latest:
# 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.
If using child modules, ensure each import uses the complete resource address path:
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.
If you have multiple imports of the same resource type, consider importing them one at a time:
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 defaultThis 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.
Once you've updated the import blocks or IDs, validate your configuration:
terraform init
terraform validate
terraform planThe init should now succeed without duplicate ID errors, and plan will show you what Terraform intends to import.
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
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform