Interview Prep/Terraform/Import Refactoring Drift and Lifecycle

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 →

  1. Import each attachment separately (aws_iam_role_policy_attachment uses role-name/policy-arn).
  2. Use exclusive resources deliberately: aws_iam_role_policy_attachments_exclusive if Terraform should be the only manager.
  3. 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".

All Terraform questions Roadmap: Terraform in production

More on Import Refactoring Drift and Lifecycle