Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error deleting S3 Bucket with Versioning Enabled: BucketNotEmpty #208

Closed
hashibot opened this issue Jun 13, 2017 · 10 comments
Closed

Error deleting S3 Bucket with Versioning Enabled: BucketNotEmpty #208

hashibot opened this issue Jun 13, 2017 · 10 comments
Labels
bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service.

Comments

@hashibot
Copy link

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 Version

Terraform v0.6.16

Affected Resource(s)

aws_s3_bucket

Terraform Configuration Files

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
  }
}

Expected Behavior

Because force_destroy = true is enabled, it should also delete the versions of the objects.

Actual Behavior

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

Steps to Reproduce

  1. Define a bucket resource
  2. terraform apply
  3. Upload some other assets to the bucket
  4. terraform destroy

Important Factoids

  • Running on AWS.
  • Bucket was created using aws cli because we also use it to store terraform remote state.

References

@hashibot hashibot added the bug Addresses a defect in current functionality. label Jun 13, 2017
@sarjuymd
Copy link

Seeing this on v0.9.11 too.

@xocasdashdash
Copy link

Can confirm the workaround that helped me with this issue (0.10.5) was:

  • Changed force_destroy to true
  • Run plan & apply
  • Changed bucket name
  • Run plan & apply
  • Change force_destroy back to false

@pmoust
Copy link
Contributor

pmoust commented Dec 18, 2017

FWIW this is still the case with 0.11.1

@scraly
Copy link

scraly commented Jan 3, 2018

Yes the issue still exists with latest version of terraform.

@radeksimko radeksimko added the service/s3 Issues and PRs that pertain to the s3 service. label Jan 25, 2018
@Ycallaer
Copy link

+1 Any idea when this issue might be resolved ?

@jasonlll88
Copy link

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

@bostrowski13
Copy link

i can confirm this also works in v0.11.14 as well

@ewbankkit
Copy link
Contributor

There have been various fixes, such as #7268, which mean that this problem should be resolved now.

@bflad
Copy link
Contributor

bflad commented Nov 25, 2019

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.

@bflad bflad closed this as completed Nov 25, 2019
@ghost
Copy link

ghost commented Mar 29, 2020

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!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service.
Projects
None yet
Development

No branches or pull requests