🎉 DevOps Interview Prep Bundle is live — 1000+ Q&A across 20 topicsGet it →
All Fixes
Today I Fixed

Terraform: BucketAlreadyOwnedByYou error on S3 bucket creation

terraformJun 23, 202610 minutes to fixterraformawstroubleshooting

Running terraform apply on a new workspace:

Error: creating S3 Bucket (my-app-artifacts): BucketAlreadyOwnedByYou: 
Your previous request to create the named bucket succeeded and you already own it.

What happened: The S3 bucket already existed in AWS (created manually earlier) but wasn't in the Terraform state. Terraform tried to create it fresh and hit the conflict.

Option 1: Import the existing bucket into state

This is the right approach if you want Terraform to manage the existing bucket:

bash
terraform import aws_s3_bucket.artifacts my-app-artifacts

After import, terraform plan should show no changes (or only differences between real config and your Terraform code).

Option 2: Delete the manual bucket and let Terraform create it

Only if the bucket is empty and you don't need its contents:

bash
aws s3 rb s3://my-app-artifacts --force
terraform apply

Option 3: Use data source instead of resource

If you don't want Terraform managing the bucket (just referencing it):

hcl
# Instead of:
resource "aws_s3_bucket" "artifacts" {
  bucket = "my-app-artifacts"
}
 
# Use:
data "aws_s3_bucket" "artifacts" {
  bucket = "my-app-artifacts"
}

Data sources read existing resources without creating/managing them.

Lesson: Before creating resources with Terraform, check if they already exist in AWS. Use terraform import to bring existing AWS resources under Terraform management rather than recreating them.

Did this fix work?

Tell us what needs improving. No account required.