Importing an `aws_iam_role_policy_attachment` fails with `unexpected format for ID`.
IntermediateTroubleshootingImport, Already Exists and State Surgery
Answer
Likely causes → Many "association" resources use composite IDs, not a single AWS ID. For this one it's role-name/policy-arn.
Diagnose → Check the "Import" section at the bottom of the resource's provider documentation page.
Fix →
import {
to = aws_iam_role_policy_attachment.ssm
id = "app-role/arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
Other examples: aws_route_table_association uses subnet-id/rtb-id; aws_security_group_rule has a long composite ID.
Prevent → Keep a cheatsheet of composite IDs for commonly imported resources.
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