BucketNotEmpty: bucket you tried to delete is not empty Terraform Origin: Platform & cloud OSI layer 7 · Application Last updated 5 Nov 2026

Terraform: Error: deleting S3 Bucket (my-bucket): BucketNotEmpty: The bucket you tried to delete is not empty

Terraform can't delete an S3 bucket that still holds objects (or versions).

Exact message you may see Error: deleting S3 Bucket (my-bucket): BucketNotEmpty: The bucket you tried to delete is not emptyBucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucketError: error deleting S3 Bucket: BucketNotEmptyBucketNotEmpty status code: 409 terraform destroy
Seen on: Terraform AWS

Meaning

Set force_destroy = true on the bucket (applied first, then destroy), or empty it manually (aws s3 rm s3://bucket --recursive; versioned buckets need all versions/delete markers removed: aws s3api delete-objects). Protect production buckets instead with prevent_destroy.

Common causes

  • Objects/versions present
  • Versioning enabled (delete markers and old versions)
  • Logs written by other services
  • force_destroy not set
  • Object lock/retention

⚡ Quick fix

  1. force_destroy = true, terraform apply, then destroy
  2. aws s3 rm s3://BUCKET --recursive plus delete versions
  3. Keep prevent_destroy for important buckets

Detailed fix by platform

AWS

  1. aws s3 rm s3://my-bucket --recursive && aws s3api list-object-versions --bucket my-bucket --query 'Versions[].Key'

How to diagnose

  1. Objects — Present?
  2. Versions — Delete markers?
  3. Setting — force_destroy?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

DependencyViolation: resource has dependent objects (destroy) — Terraform: Error: deleting EC2 VPC (vpc-0abc): DependencyViolation: The vpc 'vpc-0abc' has dependencies and cannot be deleted (Terraform)DependencyViolation: …Error loading state: AccessDenied (S3 backend) — Terraform: Error: Failed to load state: AccessDenied: Access Denied / Error refreshing state: AccessDenied status code: 403 (Terraform)Error loading state: …Instance cannot be destroyed (lifecycle.prevent_destroy) — Terraform: Error: Instance cannot be destroyed — Resource aws_db_instance.prod has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed (Terraform)Instance cannot be de…Invalid AWS Region — Terraform: Error: Invalid AWS Region: us-east-3 / Error: configuring Terraform AWS Provider: validating provider credentials: operation error STS: GetCallerIdentity (Terraform)Invalid AWS RegionNo valid credential sources found (AWS provider) — Terraform: Error: No valid credential sources found — failed to refresh cached credentials, no EC2 IMDS role found / Error: configuring Terraform AWS Provider: no valid credential sources (Terraform)No valid credential s…S3 backend: NoSuchBucket / bucket does not exist — Terraform: Error: Failed to get existing workspaces: S3 bucket "my-tf-state" does not exist / NoSuchBucket: The specified bucket does not exist (Terraform)S3 backend: NoSuchBuc…UnauthorizedOperation / AccessDenied during Terraform apply — Terraform: Error: creating EC2 Instance: UnauthorizedOperation: You are not authorized to perform this operation. User: arn:aws:iam::123:user/ci is not authorized to perform: ec2:RunInstances (Terraform)UnauthorizedOperation…BucketNot…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.