_This issue was originally opened by @osterman as hashicorp/terraform#7854. It was migrated here as part of the provider split. The original body of the issue is below._
Terraform v0.6.16
aws_s3_bucket
resource "aws_s3_bucket" "storage" {
bucket = "storage.${var.dns_zone}"
acl = "private"
force_destroy = true
versioning {
enabled = true
}
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect":"Allow",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::storage.${var.dns_zone}", "arn:aws:s3:::storage.${var.dns_zone}/*"],
"Principal": "*",
"Condition": {
"StringEquals": {
"aws:sourceVpce": "${aws_vpc_endpoint.s3.id}"
}
}
}
]
}
EOF
tags {
Name = "${var.namespace}-storage"
Namespace = "${var.namespace}"
Role = "storage"
Stage = "${var.stage}"
}
lifecycle {
create_before_destroy = true
}
}
Because force_destroy = true
is enabled, it should also delete the versions of the objects.
Error applying plan:
1 error(s) occurred:
* aws_s3_bucket.storage: Error deleting S3 Bucket: BucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucket.
status code: 409, request id: 9AE6E70339A97B62
terraform apply
terraform destroy
Bucket was created using aws cli
because we also use it to store terraform remote state.
The ability to force delete a bucket was requested here: https://github.com/hashicorp/terraform/issues/1977
Seeing this on v0.9.11 too.
Can confirm the workaround that helped me with this issue (0.10.5) was:
FWIW this is still the case with 0.11.1
Yes the issue still exists with latest version of terraform.
+1 Any idea when this issue might be resolved ?
It works in Terraform v0.12.0.
I created some resources
resource "aws_s3_bucket" "terraform-state-storage-s3" {
# Remember that this name should be globally unique
bucket = "terraform-remote-state-storage-s3-example"
versioning {
enabled = true
}
lifecycle {
prevent_destroy = false
}
force_destroy = true
}
I added some files to the bucket and then run terraform destroy
it worked well
i can confirm this also works in v0.11.14 as well
There have been various fixes, such as https://github.com/terraform-providers/terraform-provider-aws/pull/7268, which mean that this problem should be resolved now.
Hi folks 👋 As mentioned above, it is likely that various scenarios have been fixed with various updates to the Terraform AWS Provider since this bug report was submitted. If you are still running into trouble running recent versions of the Terraform CLI and the Terraform AWS Provider, please open a new bug report following the issue template and we will take a further look. Thanks.
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
Yes the issue still exists with latest version of terraform.