terraform-aws-tfstate-backend
terraform-aws-tfstate-backend copied to clipboard
Logging bucket generates a name with a duplicate
Found a bug? Maybe our Slack Community can help.
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
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.
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
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.
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.