Terraform "creating S3 Bucket: BucketAlreadyExists" in CI
By Daniel Zoghalchali·Latchkey
S3 bucket names are globally unique across all AWS accounts. Terraform tried to create a bucket whose name is already owned -- by someone else (BucketAlreadyExists) or by you (BucketAlreadyOwnedByYou).
What this error means
apply fails creating an aws_s3_bucket with BucketAlreadyExists or BucketAlreadyOwnedByYou. It surfaces when a static bucket name collides globally, or when a bucket you already own is not in Terraform state.
terraform
Error: creating S3 Bucket (my-app-bucket): operation error S3: CreateBucket,
https response error StatusCode: 409, BucketAlreadyExists: The requested bucket
name is not available. The bucket namespace is shared by all users of the system.
with aws_s3_bucket.assets,
on s3.tf line 1, in resource "aws_s3_bucket" "assets":
Diagnose it: init, state, or credentials?
Terraform failures in CI are dominated by backend and credential problems rather than configuration errors. Confirm the runner can initialise, authenticate, and lock state before reading the plan.
If you own the bucket (BucketAlreadyOwnedByYou), import it instead of recreating.
Run terraform import aws_s3_bucket.assets my-app-bucket.
Re-run plan to confirm no recreation is proposed.
How to prevent it
Derive bucket names from account ID/region for global uniqueness.
Use bucket_prefix to let AWS append a unique suffix.
Import pre-existing buckets rather than letting apply recreate them.
Frequently asked questions
What causes Terraform "creating S3 Bucket: BucketAlreadyExists" in CI?
There are 2 common causes: name already taken globally and bucket you own is not in state. S3 bucket names share one global namespace; a common static name is likely owned by another account already.
How do I fix Terraform "creating S3 Bucket: BucketAlreadyExists" in CI?
There are 2 fixes depending on which cause you have: make the name unique or use a prefix and import a bucket you already own. Work through them in order, since the first is the most common.
What does Terraform "creating S3 Bucket: BucketAlreadyExists" in CI actually mean?
apply fails creating an aws_s3_bucket with BucketAlreadyExists or BucketAlreadyOwnedByYou.
How do I stop Terraform "creating S3 Bucket: BucketAlreadyExists" in CI happening again?
Derive bucket names from account ID/region for global uniqueness. The prevention section lists 3 changes that keep it from recurring.