An IAM role with five policy attachments is imported, and the plan wants to change policies. What did you miss?
AdvancedScenarioImport Refactoring Drift and Lifecycle
Answer
Situation read → Importing the role does not import its attachments or inline policies.
What I'd do →
- Import each attachment separately (
aws_iam_role_policy_attachmentusesrole-name/policy-arn). - Use exclusive resources deliberately:
aws_iam_role_policy_attachments_exclusiveif Terraform should be the only manager. - Re-plan until clean.
Why → In the AWS provider each attachment is its own resource; mixing inline managed_policy_arns and attachments produces fights.
Interview tip → Know whether a resource is "authoritative" (manages the whole set) or "additive".
More on Import Refactoring Drift and Lifecycle
An S3 bucket was created by hand in the console and now must be managed by Terraform. How do you bring it in?BeginnerYou must adopt 200 existing resources and don't want to write all the HCL by hand.IntermediateHow do you find out that someone changed infrastructure outside Terraform?BeginnerSomeone opened port 22 on a security group in the console. Terraform wants to remove it. What's your process?IntermediateAn Auto Scaling group's desired capacity is changed by autoscaling, and Terraform keeps resetting it.IntermediateHow do you protect a production database from an accidental `terraform destroy`?Beginner