cloudposse / terraform-aws-tfstate-backend

Terraform module that provision an S3 bucket to store the `terraform.tfstate` file and a DynamoDB table to lock the state file to prevent concurrent modifications and state corruption.
https://cloudposse.com/accelerate
Apache License 2.0
408 stars 177 forks source link

Logging bucket generates a name with a duplicate #106

Closed johncblandii closed 1 year ago

johncblandii commented 3 years ago

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

lmf-mx commented 2 years ago

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.

nitrocode commented 2 years ago

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

ericluria commented 2 years ago

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.

Nuru commented 1 year ago

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.