CodexBloom - Programming Q&A Platform

Terraform 1.4.0: Resource Not Being Destroyed Despite Lifecycle Configuration

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

I'm not sure how to approach I'm running into an issue where a resource is not being destroyed as expected even though I've set the `lifecycle` block with `prevent_destroy = false`..... I'm using Terraform 1.4.0 for managing my AWS infrastructure. Here's the relevant part of my configuration: ```hcl resource "aws_s3_bucket" "my_bucket" { bucket = "my-unique-bucket-name" acl = "private" lifecycle { prevent_destroy = false } } ``` In my code, I have an `aws_s3_bucket` resource that I want to delete, but when I run `terraform destroy`, I keep getting the message: ``` Terraform will perform the following actions: # aws_s3_bucket.my_bucket will be destroyed - resource "aws_s3_bucket" "my_bucket" { - id = "my-unique-bucket-name" - bucket = "my-unique-bucket-name" - acl = "private" } } Plan: 0 to add, 0 to change, 1 to destroy. ``` But upon confirming the destruction, it seems to hang and doesn't actually remove the resource. After the operation, running `terraform apply` still shows the bucket as existing. I’ve checked for any dependencies on the bucket, and I don’t see any resources referencing it. I've even tried adding a `depends_on` attribute to force the dependency resolution, but it hasn’t helped. Here’s what I tried: 1. Running `terraform refresh` to sync the state. 2. Manually deleting the bucket via the AWS console, which works fine, but then the state file becomes out of sync. 3. Using `terraform taint aws_s3_bucket.my_bucket` followed by `terraform apply`, but that didn’t change anything either. Does anyone have insights on why the resource is not being destroyed or if there are other lifecycle settings I might be missing? Thanks! For reference, this is a production web app. Has anyone else encountered this? For reference, this is a production mobile app. Any ideas what could be causing this? I recently upgraded to Hcl 3.10. Any examples would be super helpful.