terraform-aws-tfstate-backend icon indicating copy to clipboard operation
terraform-aws-tfstate-backend copied to clipboard

Logging bucket generates a name with a duplicate

Open johncblandii opened this issue 4 years ago • 2 comments

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

Turning on the logging bucket creates a bucket named: nmspc-as1-root-nmspc-as1-root-tfstate-logs.

Expected Behavior

A name like: nmspc-as1-root-tfstate-logs.

Steps to Reproduce

module "tfstate_backend" {
  source  = "cloudposse/tfstate-backend/aws"
  version = "0.38.0"

  enable_server_side_encryption = var.enable_server_side_encryption
  force_destroy                 = var.force_destroy
  logging_bucket_enabled        = true
  prevent_unencrypted_uploads   = var.prevent_unencrypted_uploads

  context = module.this.context
}

Screenshots

N/A

Environment (please complete the following information):

All envs are impacted starting with v0.38.0.

Additional Context

Culprit: #104

johncblandii avatar Nov 09 '21 06:11 johncblandii

The pattern I'm seeing attempted to create a bucket name with is [namespace]-[environment]-[state]-[namespace]-[environment]-[state]-[name]-[attributes]-logs-[attributes]. I suspect something is happening in the s3-log-storage module.

lmf-mx avatar May 20 '22 15:05 lmf-mx

Hmm, most likely because we override the name

https://github.com/cloudposse/terraform-aws-tfstate-backend/blob/107da1504b7e7fd32a536cfae59602d67d654b39/main.tf#L47-L50

https://github.com/cloudposse/terraform-aws-tfstate-backend/blob/107da1504b7e7fd32a536cfae59602d67d654b39/main.tf#L150

so the example name nmspc-as1-root-nmspc-as1-root-tfstate-logs

Follows the format [name]-[environment]-[stage]-[attributes]-logs where the name is nmspc-as1-root-nmspc

nitrocode avatar Jun 23 '22 21:06 nitrocode

I think the issue is that both parameters name and context are provided to the cloudposse/s3-log-storage/aws module here. Removing the context parameter and only providing the name should fix the issue.

ericluria avatar Oct 14 '22 17:10 ericluria

This is an example of one reason why we are moving away from creating supporting resources (like a log bucket) inside the module. This will be removed in the next major release.

Nuru avatar Apr 13 '23 05:04 Nuru