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).
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 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_destroynot set- Object lock/retention
⚡ Quick fix
force_destroy = true,terraform apply, then destroyaws s3 rm s3://BUCKET --recursiveplus delete versions- Keep
prevent_destroyfor important buckets
Detailed fix by platform
AWS
aws s3 rm s3://my-bucket --recursive && aws s3api list-object-versions --bucket my-bucket --query 'Versions[].Key'
How to diagnose
- Objects — Present?
- Versions — Delete markers?
- 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:
Similar errors
- DependencyViolation: resource has dependent objects (destroy) Terraform: Error: deleting EC2 VPC (vpc-0abc): DependencyViolation: The vpc 'vpc-0abc' has dependencies and cannot be deleted
- Error loading state: AccessDenied (S3 backend) Terraform: Error: Failed to load state: AccessDenied: Access Denied / Error refreshing state: AccessDenied status code: 403
- 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
Most viewed in Terraform
- Error acquiring the state lock Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked
- Inconsistent dependency lock file Terraform: Error: Inconsistent dependency lock file — provider x: required by this configuration but no version is selected
- Reference to undeclared resource Terraform: Error: Reference to undeclared resource / Reference to undeclared input variable
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026