CodexBloom - Programming Q&A Platform

Terraform implementation guide AWS S3 Bucket Policy After State Change

๐Ÿ‘€ Views: 1801 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-20
terraform aws s3 bucket-policy HCL

I'm relatively new to this, so bear with me. I've been banging my head against this for hours... I'm working with an scenario where my Terraform configuration for an AWS S3 bucket policy does not update after I modify the policy in the code. I have defined the S3 bucket and policy in a module, and when I make changes to the policy and run `terraform apply`, it shows no changes detected, even though I expect it to update. Hereโ€™s the relevant code snippet for my S3 bucket and policy: ```hcl module "s3_bucket" { source = "./modules/s3_bucket" bucket_name = "my-unique-bucket-name" } resource "aws_s3_bucket_policy" "bucket_policy" { bucket = module.s3_bucket.bucket_name policy = jsonencode({ Version = "2012-10-17" Statement = [ { Effect = "Allow" Principal = "*" Action = "s3:GetObject" Resource = "${module.s3_bucket.bucket_arn}/*" } ] }) } ``` Initially, I had allowed `s3:PutObject` in the policy, and after testing, I decided to remove it. When I update the policy in my code and run `terraform apply`, it says: ``` No changes detected ``` I have ensured that I am in the correct workspace and that the state file is current. The module is being called correctly, and I see no errors in the logs. Iโ€™ve tried running `terraform taint` on the `aws_s3_bucket_policy.bucket_policy` resource, but that didnโ€™t help either. Is there something I'm missing in how Terraform handles updates for S3 bucket policies? How can I enforce an update to the policy so that it reflects the changes made in the code? This is happening in both development and production on CentOS. Thanks for any help you can provide! I recently upgraded to Hcl LTS. I'm open to any suggestions.