terraform-provider-aws: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
This issue was originally opened by @fubarbaz as hashicorp/terraform#10692. It was migrated here as part of the provider split. The original body of the issue is below.
Terraform 0.7.13 generates:
* aws_s3_bucket.foo: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
after I imported the resource, and specified it in the main.tf Terraform file. I would like to know how I can use a bucket named “foo” which has been created manually and essentially import it (obviously, I already imported it per documentation). So, perhaps it’s the import feature which doesn’t work.
An alternative way to get into this state is deleting the terraform state files, importing the S3 resource after that, adding it to the configuration and running terraform apply.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 25 (3 by maintainers)
Happening for me as well with the latest release
Seeing in Terraform v0.11.11 too
Seeing in Terraform v0.11.10
Seeing it in v0.11.7
Seeing it in v0.11.8
Hi folks 👋
If you are encountering a
BucketAlreadyOwnedByYouerror with theaws_s3_bucketresource, this means that the S3 Bucket was previously created by some other means (potentially another part of your Terraform configuration) and that you will either need to import the existing S3 Bucket configuration into Terraform or use theaws_s3_bucketdata source instead of theaws_s3_bucketresource. Which fix is correct for your environment will be specific to what you are trying to accomplish in your Terraform configuration.Terraform expects only one source of truth for managing a single piece of infrastructure. While you can technically import a Terraform resource in multiple places (at the moment), their configurations will perpetually conflict with each other if there are differences.
If you are attempting to read-only reference the existing S3 Bucket, replace the resource configuration with a data source configuration. e.g.
If you are instead attempting to manage the existing S3 Bucket, the following command can be used to import this resource into Terraform (as documented in the
Importsection of theaws_s3_bucketresource documentation):We have a current proposal out to start catching errors like these and provide better guidance on what to do in these situations: #9223
Hopefully this helps clear up any confusion. If you’re looking for general assistance, please note that we use GitHub issues in this repository for tracking bugs and enhancements with the Terraform AWS Provider codebase rather than for questions. While we may be able to help with certain simple problems here it’s generally better to use one of the community forums where there are far more people ready to help, whereas the GitHub issues here are generally monitored only by a few maintainers and dedicated community members interested in code development of the Terraform AWS Provider itself.
@aterreno - thanks. I actually fixed my own issue, but as a total noob to terraform shall try to share what I know.
So I was getting weird situation whereby if I didn’t create the s3 bucket explicitly, i got an error about the s3 bucket does not exist yet. And then when i manually added the bucket, i got an error as described here (about already owned bla bla bla).
It turns out I think I misconfigured my remote backend. I inadvertently gave it the same s3 bucket as the s3 resource I was creating with terraform…
Simplified extract:
By commenting out the terraform backend declaration (effectively getting rid of the remote state management), doing a
rm -rf .terraform, and then the usualterraform init, terraform plan, terraform applysequence it sorted itself out.As of AWS provider version 1.1.0, there is a data source for
aws_s3_bucket: https://www.terraform.io/docs/providers/aws/d/s3_bucket.html@kinowarrior see @bflad answer, https://www.terraform.io/docs/providers/aws/d/s3_bucket.html that would do it
Seeing in Terraform v0.11.13 too aws provider version 2.4.0