Interview Prep/Terraform/Plan Errors and Unexpected Replacements

Plans show `~ policy` changes for an S3 bucket policy built with `jsonencode()` because principal values flip between `"123456789012"` and `"arn:aws:iam::123456789012:root"`.

IntermediateTroubleshootingPlan Errors and Unexpected Replacements
Answer

Likely causes → AWS stores principals in normalized ARN form; your code uses a bare account ID.

Diagnose → Compare aws s3api get-bucket-policy output with your code.

Fix → Write principals in full ARN form, or build the policy with data "aws_iam_policy_document", which the provider compares semantically.

Prevent → Use policy document data sources for every IAM/S3/KMS policy.

All Terraform questions

More on Plan Errors and Unexpected Replacements