CodexBloom - Programming Q&A Platform

Terraform AWS S3 bucket lifecycle policy not applying as expected

👀 Views: 22 💬 Answers: 1 📅 Created: 2025-06-06
terraform aws s3 lifecycle-policy HCL

I tried several approaches but none seem to work... I'm working on a Terraform script to configure an S3 bucket with a lifecycle policy that transitions objects to Glacier after 30 days. However, after applying the configuration, I find that the lifecycle policy isn't being applied to the bucket. Here's the relevant part of my Terraform code: ```hcl resource "aws_s3_bucket" "my_bucket" { bucket = "my-unique-bucket-name" } resource "aws_s3_bucket_lifecycle_configuration" "my_bucket_lifecycle" { bucket = aws_s3_bucket.my_bucket.id rule { id = "TransitionToGlacier" status = "Enabled" transition { days = 30 storage_class = "GLACIER" } } } ``` I've run `terraform apply`, and it shows that the resources are created successfully, but when I check the S3 bucket in the AWS console, the lifecycle policy doesn't appear to be applied. I've also tried refreshing the state using `terraform refresh`, but that didn't change anything. Additionally, I checked my IAM permissions, and they seem fine as I'm able to create the bucket without any issues. I’ve ensured that my AWS provider version is compatible, as I'm using `provider "aws" { version = "~> 3.0" }`. Is there something I might be missing in my configuration, or could there be an scenario with the way Terraform interacts with S3 lifecycle policies? Any help would be greatly appreciated! Any help would be greatly appreciated! For context: I'm using Hcl on Linux. How would you solve this?