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:
terraform import aws_s3_bucket.artifacts my-app-artifactsAfter 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:
aws s3 rb s3://my-app-artifacts --force
terraform applyOption 3: Use data source instead of resource
If you don't want Terraform managing the bucket (just referencing it):
# 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.