You need to import 60 SQS queues created by hand. Writing 60 import blocks is error-prone.
IntermediateTroubleshootingImport, Already Exists and State Surgery
Answer
Likely causes → Not an error, but a common place to make address mistakes.
Diagnose → List the real queues: aws sqs list-queues --queue-name-prefix orders- --query QueueUrls
Fix → Use for_each on import blocks (Terraform 1.7+), driven by the same map as the resource:
locals {
queues = toset(["orders-created", "orders-paid", "orders-shipped"])
}
resource "aws_sqs_queue" "q" {
for_each = local.queues
name = each.key
}
import {
for_each = local.queues
to = aws_sqs_queue.q[each.key]
id = "https://sqs.ap-south-1.amazonaws.com/111122223333/${each.key}"
}
Prevent → Delete import blocks after a clean apply, or leave them; they're no-ops once imported.
More on Import, Already Exists and State Surgery
Apply fails with `EntityAlreadyExists: Role with name app-role already exists.`Beginner`terraform apply` on a new bucket fails with `BucketAlreadyExists`. You have never created that bucket.Beginner`Error: Resource already managed by Terraform` when running `terraform import aws_s3_bucket.logs acme-logs`.Beginner`Error: Cannot import non-existent remote object` for a resource you can see in the console.Intermediate`Error: Configuration for import target does not exist` when running `terraform plan` with an `import` block.Beginner`terraform plan -generate-config-out=generated.tf` fails with `Conflicting configuration arguments` in the generated file.Intermediate