diff --git a/logs_monitoring_cloudwatch_log.tf b/logs_monitoring_cloudwatch_log.tf index 87c70b5..b5b4a22 100644 --- a/logs_monitoring_cloudwatch_log.tf +++ b/logs_monitoring_cloudwatch_log.tf @@ -1,17 +1,17 @@ resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" { - count = length(var.cloudwatch_log_groups) - name = "${var.cloudwatch_log_groups[count.index]}-filter" - log_group_name = var.cloudwatch_log_groups[count.index] + for_each = { for lg in var.cloudwatch_log_groups : lg => lg } + name = "${each.value}-filter" + log_group_name = each.value filter_pattern = "" destination_arn = aws_cloudformation_stack.datadog-forwarder.outputs.DatadogForwarderArn distribution = "Random" } resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" { - count = length(var.cloudwatch_log_groups) - statement_id = "${substr(replace(var.cloudwatch_log_groups[count.index], "/", "_"), 0, 67)}-AllowExecutionFromCloudWatchLogs" + for_each = { for lg in var.cloudwatch_log_groups : lg => lg } + statement_id = "${substr(replace(each.value, "/", "_"), 0, 67)}-AllowExecutionFromCloudWatchLogs" action = "lambda:InvokeFunction" function_name = aws_cloudformation_stack.datadog-forwarder.outputs.DatadogForwarderArn principal = "logs.${var.aws_region}.amazonaws.com" - source_arn = "arn:aws:logs:${var.aws_region}:${var.aws_account_id}:log-group:${var.cloudwatch_log_groups[count.index]}:*" + source_arn = "arn:aws:logs:${var.aws_region}:${var.aws_account_id}:log-group:${each.value}:*" }