Git Product home page Git Product logo

Error: Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again. about terraform-aws-tfstate-backend HOT 15 CLOSED

cloudposse avatar cloudposse commented on June 5, 2024 1
Error: Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.

from terraform-aws-tfstate-backend.

Comments (15)

abulava avatar abulava commented on June 5, 2024 29

@sev3ryn Note that S3 bucket names must be globally unique amongst all AWS customers.

from terraform-aws-tfstate-backend.

jamengual avatar jamengual commented on June 5, 2024 10

Hi @organicnz This is normal behavior with S3 buckets, when buckets have deleted the names takes some time to be released so that it can be reused, this is not a bug on the module or terraform, this is how the AWS S3 api works

from terraform-aws-tfstate-backend.

sev3ryn avatar sev3ryn commented on June 5, 2024 7

I have same issue - I'm creating bucket that never existed before with just random name but receive Error creating S3 bucket: BucketAlreadyExists

from terraform-aws-tfstate-backend.

ardarm avatar ardarm commented on June 5, 2024 2

To make your bucket name unique, you can add random string after attributes. In my case, i define it like this

resource "random_string" "random" {
  length  = 12
  upper   = false
  number  = false
  lower   = true
  special = false
}

module "terraform_state_backend" {
  source = "cloudposse/tfstate-backend/aws"
  # Cloud Posse recommends pinning every module to a specific version
  version    = "0.33.1"
  namespace  = "eg"
  stage      = "test"
  name       = "terraform"
  attributes = ["state-${random_string.random.result}"]

  terraform_backend_config_file_path = "."
  terraform_backend_config_file_name = "backend.tf"
  force_destroy                      = false
}

This is more easier than searching new unique name since S3 bucket name is globally unique.

from terraform-aws-tfstate-backend.

tusharrverma16 avatar tusharrverma16 commented on June 5, 2024 2

@sev3ryn Note that S3 bucket names must be globally unique amongst all AWS customers.

thanks for reminding, it helped :)
cheers!

from terraform-aws-tfstate-backend.

jamengual avatar jamengual commented on June 5, 2024 1

@organicnz is you did not destroy the bucket before creating this is going to happen.
this is not a bug AFAIK

from terraform-aws-tfstate-backend.

jamengual avatar jamengual commented on June 5, 2024 1

are you cleaning the .terraform dir and such when switching to another region? this is to create the bucket for the state to be stored so it should not exist in the state until is created.

I will assume you switched to another region because you do not have a state so in that case, you need to reinitialize the project which can be done by rm -rf .terraform and then terraform init and then apply or plan

from terraform-aws-tfstate-backend.

sev3ryn avatar sev3ryn commented on June 5, 2024 1

yes, thanks, thats was it. Interesting what is aws reasoning behind that if bucket is not even public :)

from terraform-aws-tfstate-backend.

organicnz avatar organicnz commented on June 5, 2024

@organicnz is you did not destroy the bucket before creating this is going to happen.
this is not a bug AFAIK

Just tried it again and it spews the same error :)

terraform destroy -refresh=false
var.region
  AWS Region the S3 bucket should reside in

  Enter a value: us-west-2

provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Enter a value: us-west-2

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes


Destroy complete! Resources: 0 destroyed.
terraform apply -auto-approve   
var.region
  AWS Region the S3 bucket should reside in

  Enter a value: us-west-2

provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Enter a value: us-west-2

data.aws_iam_policy_document.prevent_unencrypted_uploads[0]: Refreshing state...
module.terraform_state_backend.data.aws_iam_policy_document.prevent_unencrypted_uploads[0]: Refreshing state...
module.terraform_state_backend.aws_dynamodb_table.with_server_side_encryption[0]: Creating...
aws_dynamodb_table.with_server_side_encryption[0]: Creating...
module.terraform_state_backend.aws_s3_bucket.default: Creating...
aws_s3_bucket.default: Creating...
module.terraform_state_backend.aws_dynamodb_table.with_server_side_encryption[0]: Still creating... [10s elapsed]
aws_dynamodb_table.with_server_side_encryption[0]: Still creating... [10s elapsed]
module.terraform_state_backend.aws_dynamodb_table.with_server_side_encryption[0]: Creation complete after 10s [id=eg-test-terraform-state-lock]
aws_dynamodb_table.with_server_side_encryption[0]: Creation complete after 12s [id=terraform-state-lock]

Error: Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
        status code: 409, request id: 4A229001A6A1EA6C, host id: LlszF09zWpcTVFKP0IEWt52qEFMjHbFSwtfU8W0S7scUK53fjrG2ACyY7QDwGgFkvmMh6t9uuj8=

  on main.tf line 145, in resource "aws_s3_bucket" "default":
 145: resource "aws_s3_bucket" "default" {

Error: Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
        status code: 409, request id: 59E964BDAA48DCDD, host id: aKpwR55Nh0aRFwAIv6Y8QQkMcnmZWSUFOLuvL5nmO4Bh+eOSAayCmXE1zrIHT66Faah1/VfglMA=

  on .terraform/modules/terraform_state_backend/main.tf line 124, in resource "aws_s3_bucket" "default":
 124: resource "aws_s3_bucket" "default" {

from terraform-aws-tfstate-backend.

organicnz avatar organicnz commented on June 5, 2024

Hi @organicnz This is normal behavior with S3 buckets, when buckets have deleted the names takes some time to be released so that it can be reused, this is not a bug on the module or terraform, this is how the AWS S3 api works

Yeah, looks like it is, still cleaning up S3 buckets in region us-west-2, but when it passed that step in us-west-1 or us-east-1 it drops another error with coalescelist. Someone mentioned that it should rely on the conditional operator on a thread.

terraform apply -auto-approve                                                   

var.region
  AWS Region the S3 bucket should reside in

  Enter a value: us-west-1

provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Enter a value: us-west-1

module.terraform_state_backend.data.aws_iam_policy_document.prevent_unencrypted_uploads[0]: Refreshing state...
data.aws_iam_policy_document.prevent_unencrypted_uploads[0]: Refreshing state...
aws_dynamodb_table.with_server_side_encryption[0]: Refreshing state... [id=terraform-state-lock]
module.terraform_state_backend.aws_dynamodb_table.with_server_side_encryption[0]: Refreshing state... [id=eg-test-terraform-state-lock]

Error: Error in function call

  on main.tf line 255, in data "template_file" "terraform_backend_config":
 255:       coalescelist(
 256: 
 257: 
 258: 
    |----------------
    | aws_dynamodb_table.with_server_side_encryption is empty tuple
    | aws_dynamodb_table.without_server_side_encryption is empty tuple

Call to function "coalescelist" failed: no non-null arguments.


Error: Error in function call

  on .terraform/modules/terraform_state_backend/main.tf line 234, in data "template_file" "terraform_backend_config":
 234:       coalescelist(
 235: 
 236: 
 237: 
    |----------------
    | aws_dynamodb_table.with_server_side_encryption is empty tuple
    | aws_dynamodb_table.without_server_side_encryption is empty tuple

Call to function "coalescelist" failed: no non-null arguments.

from terraform-aws-tfstate-backend.

organicnz avatar organicnz commented on June 5, 2024

are you cleaning the .terraform dir and such when switching to another region? this is to create the bucket for the state to be stored so it should not exist in the state until is created.

I will assume you switched to another region because you do not have a state so in that case, you need to reinitialize the project which can be done by rm -rf .terraform and then terraform init and then apply or plan

Thank you, I haven't cleaned it up before you mentioned and my deep apologies that it's not a bug as it was labelled initially.
That's so weird it shows empty S3 storage, but the issue doesn't disappear anywhere. Should this error be rather addressed to AWS?

#Error: Error creating S3 bucket: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
        status code: 409, request id: C83D6B33B66E5AD0, host id: nsXFCzCdd2+HJUyPrrHIQokq735AEYzTntQPdNUY7OOBF+GSd5WrljJKto7LyyThoCsBCIt3LIQ=

  on .terraform/modules/terraform_state_backend/main.tf line 124, in resource "aws_s3_bucket" "default":
 124: resource "aws_s3_bucket" "default" {

from terraform-aws-tfstate-backend.

ngtuna avatar ngtuna commented on June 5, 2024

Any conclusion ? I got same weird BucketAlreadyExists error

from terraform-aws-tfstate-backend.

organicnz avatar organicnz commented on June 5, 2024

Any conclusion ? I got same weird BucketAlreadyExists error

Hi mate, have you tried to create a new unique S3 bucket? I tried on a different AWS account and it helped to resolve this issue :)

from terraform-aws-tfstate-backend.

nitrocode avatar nitrocode commented on June 5, 2024

This doesn't seem like an issue with this module as this module cannot ensure that the bucket name is unique globally

from terraform-aws-tfstate-backend.

dondeswetha avatar dondeswetha commented on June 5, 2024

Error: creating S3 Bucket (swethabuckets7128834): operation error S3: CreateBucket, https response error StatusCode: 409, RequestID: 08J2B14W7G3ZB0D0, HostID: CegKwKnfuzghXHKd7N0RI7VlOVzYUVNErrFDzhtg/+hzWMs8KUF3Jeq1m9PEydPJMx6nuSzQZsFYEjICOjWsJw==, BucketAlreadyOwnedByYou:

Getting above error while changing tfstate file to remote.

from terraform-aws-tfstate-backend.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.