Interview Prep/Terraform/Import, Already Exists and State Surgery

`terraform apply` on a new bucket fails with `BucketAlreadyExists`. You have never created that bucket.

BeginnerTroubleshootingImport, Already Exists and State Surgery
Answer

Likely causes → S3 bucket names are global across all AWS accounts; someone else owns the name. (BucketAlreadyOwnedByYou means it's in your account.)

Diagnose → aws s3api head-bucket --bucket logs → 403 means it exists elsewhere, 404 means free.

Fix → Choose a unique name, for example acme-prod-logs-${data.aws_caller_identity.current.account_id}, or use bucket_prefix.

Prevent → A naming module that always appends account ID and region to bucket names.

All Terraform questions Roadmap: Terraform in production

More on Import, Already Exists and State Surgery