TerraForm Issues: "Error creating S3 bucket: BucketAlreadyExists"

Hello!

I am struggling to understand a proposed solution to my issue in the Ceramic Discord.

Issue
terraform apply -var-file="vars.tfvars" results in the following output:

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: XXXXXX, host id: XXXXXXX

  on .terraform/modules/ceramic_ecs.ceramic.s3_alb/main.tf line 5, in resource "aws_s3_bucket" "this":
   5: resource "aws_s3_bucket" "this" {

Proposed Solution
In Ceramic’s discord, an thread (#running-a-node>#terraform-aws-ceramic-issues) between an individual and core dev @Moshin#3481, it was determined that the issue had to do with namespace overlapping. The individual with the issue reported that they were erroneously trying to create ceramic-elp-1-1-node-alb, though I do not understand the issue nor what causes it based on the discussion.

Any help or clarification would be greatly appreciated :slight_smile:

Thanks for your post, @jp4g!

The reason this is happening is that S3 bucket names use a global namespace and so if a bucket with the same name exists anywhere, AWS will throw an error.

In the Terraform module’s example main.tf, I’d suggest changing the base_namespace to be something that’s unique to you, instead of ${var.cohort}-${count.index + 1}.

module "ceramic_ecs" {
  source = "../../modules/ecs"
  .
  .
  .

  base_namespace                  = "${var.cohort}-${count.index + 1}"

Ah that is weird! So my code was

module "ceramic_ecs" {
  source = "./modules/ecs"
  count = var.deployments
  .
  .
  .
  base_namespace = "${var.cohort}-${var.deployments + 1}"

Changing it to

module "ceramic_ecs" {
  source = "./modules/ecs"
  count = var.deployments
  .
  .
  .
  base_namespace = "${var.cohort}-${count.index + 1}"

Solved this issue! Thank you!

1 Like