CodexBloom - Programming Q&A Platform

Terraform Not Applying IAM Policy Changes in AWS Despite Successful Plan

👀 Views: 81 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-20
terraform aws iam HCL

I'm facing an issue where my Terraform configuration for AWS IAM roles is not applying changes to the policy document as expected. I've updated the inline policy for an IAM role to include additional permissions, but when I run `terraform apply`, it shows that no changes are necessary, even though the plan indicates otherwise. Here's the relevant snippet of my Terraform code: ```hcl resource "aws_iam_role" "my_role" { name = "my-role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [{ Action = "sts:AssumeRole" Effect = "Allow" Principal = { Service = "ec2.amazonaws.com" } }] }) } resource "aws_iam_policy" "my_policy" { name = "my-policy" description = "My custom policy" policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = ["s3:ListBucket", "s3:GetObject"], Resource = "*" }] }) } resource "aws_iam_role_policy_attachment" "my_role_policy_attachment" { role = aws_iam_role.my_role.name policy_arn = aws_iam_policy.my_policy.arn } ``` After running `terraform plan`, I see the message: ``` Plan: 0 to add, 0 to change, 0 to destroy. ``` But I know for certain that I've made changes to the policy document. I've also tried running `terraform refresh` to see if it would update the state file, but to no avail. Additionally, I'm using Terraform version 1.3.5 and the AWS provider version 4.0.0. I've double-checked the IAM policies in the AWS console to confirm that the changes are indeed not being applied. Is there something I might be missing here, or any specific command to force the changes through? Would really appreciate any insights or similar experiences! I'm developing on Windows 11 with Hcl.