From 4542181e3fcc38d98b4b680d4ecdb1d50f793d06 Mon Sep 17 00:00:00 2001 From: huss8225 Date: Mon, 14 Apr 2025 15:24:05 -0700 Subject: [PATCH] Append ElastiCache log type to CW log group name Currently, Terraform execution fails when both slow-log and engine-log are enabled simultaneously, resulting in the following name conflict error: ```The specified log group already exists``` This occurs because both logs attempt to use the same CloudWatch Log Group name. ## Resolution: This PR addresses the issue by appending the log type (slow-log or engine-log) to the CloudWatch Log Group name. This ensures unique naming for each log and resolves the conflict. ## Example: Updated `log_delivery_configuration`: ```log_delivery_configuration = { slow-log = { destination_type = "cloudwatch-logs" log_format = "json" } engine-log = { destination_type = "cloudwatch-logs" log_format = "json" } } ``` --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 98cbbb0..510eba7 100644 --- a/main.tf +++ b/main.tf @@ -225,7 +225,7 @@ locals { resource "aws_cloudwatch_log_group" "this" { for_each = { for k, v in var.log_delivery_configuration : k => v if local.create_cloudwatch_log_group && try(v.create_cloudwatch_log_group, true) && try(v.destination_type, "") == "cloudwatch-logs" } - name = "/aws/elasticache/${try(each.value.cloudwatch_log_group_name, coalesce(var.cluster_id, var.replication_group_id), "")}" + name = "/aws/elasticache/${try(each.value.cloudwatch_log_group_name, coalesce(var.cluster_id, var.replication_group_id), "")/${each.key}}" retention_in_days = try(each.value.cloudwatch_log_group_retention_in_days, 14) kms_key_id = try(each.value.cloudwatch_log_group_kms_key_id, null) skip_destroy = try(each.value.cloudwatch_log_group_skip_destroy, null)