Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add opt-in config to create order independent log filters #78

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion modules/cloudwatch-logs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
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
}
2 changes: 1 addition & 1 deletion modules/cloudwatch-logs/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions modules/cloudwatch-logs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading