Interview Prep/Terraform/Lost, Corrupted and Drifted State

An IAM policy shows changes every plan even though the JSON is "the same".

IntermediateTroubleshootingLost, Corrupted and Drifted State
Answer

Likely causes → A heredoc JSON string differs from how AWS normalizes it (statement order, single-string vs list Action, whitespace), or principals were given as account IDs that AWS rewrites to ARNs.

Diagnose → In the plan diff, look for Action = "s3:GetObject" vs Action = ["s3:GetObject"] or reordered keys.

Fix → Generate policies with data "aws_iam_policy_document" or jsonencode() and match AWS's canonical form (full ARNs for principals, lists where AWS uses lists).

Prevent → Ban raw heredoc JSON policies in code review; use policy documents everywhere.

All Terraform questions Roadmap: Terraform in production

More on Lost, Corrupted and Drifted State