Interview Prep/Terraform/Import, Already Exists and State Surgery

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.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery