Skip to content

Commit

Permalink
Merge pull request #59 from scribd/zbstof-patch-1
Browse files Browse the repository at this point in the history
Switch to for_each for log forwarding resources
  • Loading branch information
zbstof authored Feb 15, 2024
2 parents 3ca76a2 + 8f95d4b commit af7e1c2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions logs_monitoring_cloudwatch_log.tf
Original file line number Diff line number Diff line change
@@ -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}:*"
}

0 comments on commit af7e1c2

Please sign in to comment.