Terraform: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.

Created on 13 Dec 2016  路  9Comments  路  Source: hashicorp/terraform

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.

bug provideaws

Most helpful comment

I had the same error with 0.11.7. Downgrading to 0.11.5 didn't trigger the error. I wonder if this issue can be re-opened?

All 9 comments

Is anyone able to confirm whether the bug is also when it comes to updating an S3 bucket?

With the following _initial_ resource:

resource "aws_s3_bucket" "cdn_bucket" {
  acl = "public-read"
  bucket = "${var.environment}-static-assets"
  versioning = {
    enabled = true
  }

  policy = <<POLICY
{
  "Version":"2012-10-17",
  "Statement":[{
    "Sid":"PublicReadForGetBucketObjects",
      "Effect":"Allow",
      "Principal": "*",
      "Action":"s3:GetObject",
      "Resource":["arn:aws:s3:::${var.environment}-static-assets/*"
      ]
    }
  ]
}
POLICY
}

And then by adding the following (note the addition of the Environment tag):

resource "aws_s3_bucket" "cdn_bucket" {
  acl = "public-read"
  bucket = "${var.environment}-static-assets"
  versioning = {
    enabled = true
  }

  policy = <<POLICY
{
  "Version":"2012-10-17",
  "Statement":[{
    "Sid":"PublicReadForGetBucketObjects",
      "Effect":"Allow",
      "Principal": "*",
      "Action":"s3:GetObject",
      "Resource":["arn:aws:s3:::${var.environment}-static-assets/*"
      ]
    }
  ]
}
POLICY
  tags {
    Environment = "${var.environment}"
  }
}

Then I get:

* aws_s3_bucket.cdn_bucket: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.
    status code: 409, request id: <<request_id>>

Can confirm getting this while updating the bucket. Terraform 0.9.2

Terraform version: 0.9.5 dev
confirmed too

  • module.s3.aws_s3_bucket.default: 1 error(s) occurred:
  • aws_s3_bucket.default: Error creating S3 bucket: BucketAlreadyOwnedByYou: Your previous request to create the named bucket succeeded and you already own it.

even if the import is a "succes"
Import success! The resources imported are shown above.

Error applying plan:

1 error(s) occurred:

  • module.s3.aws_s3_bucket.default: 1 error(s) occurred:

  • aws_s3_bucket.default: unexpected EOF

Faced the same issue with Terraform version 0.9.5 dev.

had the same issue on v0.11.7
I accidentally deleted .tfstate file and was not able to connect to the s3 bucket previously created with tf

I had the same error with 0.11.7. Downgrading to 0.11.5 didn't trigger the error. I wonder if this issue can be re-opened?

Happening with 0.11.8 as well

Same with Terraform v0.11.10

This issue was migrated to terraform-providers/terraform-provider-aws#423 since the AWS provider is not part of Terraform Core anymore. Please continue discussion about it over there. Thanks!

Was this page helpful?
0 / 5 - 0 ratings