diff --git a/modules/cloudwatch-logs/main.tf b/modules/cloudwatch-logs/main.tf index f7af6f9..c203c59 100644 --- a/modules/cloudwatch-logs/main.tf +++ b/modules/cloudwatch-logs/main.tf @@ -23,10 +23,21 @@ module "kfh" { } resource "aws_cloudwatch_log_subscription_filter" "this" { - count = length(var.cloudwatch_log_groups) + count = !var.use_order_independent_filter_resource_naming ? length(var.cloudwatch_log_groups) : 0 + name = "${var.cloudwatch_log_groups[count.index]}-logs_subscription_filter" role_arn = aws_iam_role.this.arn log_group_name = var.cloudwatch_log_groups[count.index] filter_pattern = var.log_subscription_filter_pattern destination_arn = module.kfh.kinesis_firehose_delivery_stream_arn } + +resource "aws_cloudwatch_log_subscription_filter" "filters" { + for_each = var.use_order_independent_filter_resource_naming ? toset(var.cloudwatch_log_groups) : [] + + name = "${each.key}-logs_subscription_filter" + role_arn = aws_iam_role.this.arn + log_group_name = each.key + filter_pattern = var.log_subscription_filter_pattern + destination_arn = module.kfh.kinesis_firehose_delivery_stream_arn +} diff --git a/modules/cloudwatch-logs/outputs.tf b/modules/cloudwatch-logs/outputs.tf index 032fa82..3e437d3 100644 --- a/modules/cloudwatch-logs/outputs.tf +++ b/modules/cloudwatch-logs/outputs.tf @@ -1,3 +1,3 @@ output "cloudwatch_log_subscription_filters" { - value = aws_cloudwatch_log_subscription_filter.this[*].name + value = var.use_order_independent_filter_resource_naming ? [for filter in aws_cloudwatch_log_subscription_filter.filters : filter.name] : aws_cloudwatch_log_subscription_filter.this[*].name } diff --git a/modules/cloudwatch-logs/variables.tf b/modules/cloudwatch-logs/variables.tf index 97be0bf..0249cce 100644 --- a/modules/cloudwatch-logs/variables.tf +++ b/modules/cloudwatch-logs/variables.tf @@ -136,3 +136,9 @@ variable "tags" { default = {} description = "A map of tags to apply to resources created by this module." } + +variable "use_order_independent_filter_resource_naming" { + type = bool + description = "Use order-independent naming for log group subscription filter resources." + default = false +}