From 3ba8901dda50f32cd665f3c56474a4d36a6767f0 Mon Sep 17 00:00:00 2001 From: Akhil Dangore Date: Mon, 2 Dec 2024 07:12:55 +0530 Subject: [PATCH 1/2] Added support for tag filter --- aws-observability-terraform/source-module/main.tf | 2 ++ aws-observability-terraform/source-module/variables.tf | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/aws-observability-terraform/source-module/main.tf b/aws-observability-terraform/source-module/main.tf index 2f69a56d..51fe40c9 100644 --- a/aws-observability-terraform/source-module/main.tf +++ b/aws-observability-terraform/source-module/main.tf @@ -165,6 +165,7 @@ module "cloudwatch_metrics_source_module" { collector_id = local.create_collector ? sumologic_collector.collector["collector"].id : var.sumologic_existing_collector_details.collector_id limit_to_namespaces = [each.value] limit_to_regions = [local.aws_region] + tag_filters = [for tag_filter in var.cloudwatch_metrics_source_details.tag_filters : tag_filter if tag_filter.namespace == each.value] paused = false scan_interval = lookup(local.namespace_scan_interval,regex("^AWS/(\\w+)$", each.value)[0],"300000") sumo_account_id = local.sumo_account_id @@ -191,6 +192,7 @@ module "kinesis_firehose_for_metrics_source_module" { description = var.cloudwatch_metrics_source_details.description collector_id = local.create_collector ? sumologic_collector.collector["collector"].id : var.sumologic_existing_collector_details.collector_id limit_to_namespaces = var.cloudwatch_metrics_source_details.limit_to_namespaces + tag_filters = [for tag_filter in var.cloudwatch_metrics_source_details.tag_filters: tag_filter if contains(var.cloudwatch_metrics_source_details.limit_to_namespaces, tag_filter.namespace)] sumo_account_id = local.sumo_account_id fields = local.metrics_fields iam_details = { diff --git a/aws-observability-terraform/source-module/variables.tf b/aws-observability-terraform/source-module/variables.tf index d082e086..c2c6888c 100644 --- a/aws-observability-terraform/source-module/variables.tf +++ b/aws-observability-terraform/source-module/variables.tf @@ -369,6 +369,11 @@ variable "cloudwatch_metrics_source_details" { source_category = string description = string limit_to_namespaces = list(string) + tag_filters = list(object({ + type = string + namespace = string + tags = list(string) + })) fields = map(string) bucket_details = object({ create_bucket = bool @@ -386,6 +391,7 @@ variable "cloudwatch_metrics_source_details" { source_category = "aws/observability/cloudwatch/metrics" description = "This source is created using Sumo Logic terraform AWS Observability module to collect AWS Cloudwatch metrics." limit_to_namespaces = ["AWS/ApplicationELB", "AWS/ApiGateway", "AWS/DynamoDB", "AWS/Lambda", "AWS/RDS", "AWS/ECS", "AWS/ElastiCache", "AWS/ELB", "AWS/NetworkELB", "AWS/SQS", "AWS/SNS", "AWS/EC2"] + tag_filters = [] fields = {} bucket_details = { create_bucket = true From bba5ef0d037746df5e3928d77119b1c8773faece Mon Sep 17 00:00:00 2001 From: Akhil Dangore Date: Tue, 3 Dec 2024 12:53:36 +0530 Subject: [PATCH 2/2] Added support for custom metric namespace --- .../source-module/local.tf | 2 ++ .../source-module/main.tf | 30 ++++++++++++++++++- .../source-module/outputs.tf | 9 ++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/aws-observability-terraform/source-module/local.tf b/aws-observability-terraform/source-module/local.tf index ae93723a..38f30467 100644 --- a/aws-observability-terraform/source-module/local.tf +++ b/aws-observability-terraform/source-module/local.tf @@ -36,6 +36,8 @@ locals { create_metric_source = var.collect_cloudwatch_metrics == "None" ? false : (local.update_metrics_source ? false : true) metrics_source_name = var.cloudwatch_metrics_source_details.source_name == "CloudWatch Metrics (Region)" ? "CloudWatch Metrics ${local.aws_region}" : var.cloudwatch_metrics_source_details.source_name metrics_fields = local.use_kf_metrics_source ? merge(var.cloudwatch_metrics_source_details.fields, { account = var.aws_account_alias }) : merge(var.cloudwatch_metrics_source_details.fields, { account = var.aws_account_alias, accountid = local.aws_account_id }) + custom_namespace = [for namespace in var.cloudwatch_metrics_source_details.limit_to_namespaces : namespace if !startswith(namespace, "AWS/")] + aws_namespace = [for namespace in var.cloudwatch_metrics_source_details.limit_to_namespaces : namespace if startswith(namespace, "AWS/")] # CloudWatch logs source updated details create_llf_logs_source = var.collect_cloudwatch_logs == "Lambda Log Forwarder" && var.cloudwatch_logs_source_url == "" diff --git a/aws-observability-terraform/source-module/main.tf b/aws-observability-terraform/source-module/main.tf index 51fe40c9..e3dd6292 100644 --- a/aws-observability-terraform/source-module/main.tf +++ b/aws-observability-terraform/source-module/main.tf @@ -149,9 +149,37 @@ module "classic_lb_module" { } } +module "cloudwatch_custom_metrics_source_module" { + depends_on = [time_sleep.wait_for_minutes] + for_each = toset(local.create_cw_metrics_source && length(local.custom_namespace) > 0 ? ["Custom"] : []) + source = "SumoLogic/sumo-logic-integrations/sumologic//aws/cloudwatchmetrics" + + create_collector = false + sumologic_organization_id = var.sumologic_organization_id + wait_for_seconds = 1 + + source_details = { + source_name = "${local.metrics_source_name} CustomMetrics" + source_category = var.cloudwatch_metrics_source_details.source_category + description = var.cloudwatch_metrics_source_details.description + collector_id = local.create_collector ? sumologic_collector.collector["collector"].id : var.sumologic_existing_collector_details.collector_id + limit_to_namespaces = local.custom_namespace + limit_to_regions = [local.aws_region] + tag_filters = [] + paused = false + scan_interval = 30000 + sumo_account_id = local.sumo_account_id + fields = local.metrics_fields + iam_details = { + create_iam_role = false + iam_role_arn = local.create_iam_role ? aws_iam_role.sumologic_iam_role["sumologic_iam_role"].arn : var.existing_iam_details.iam_role_arn + } + } +} + module "cloudwatch_metrics_source_module" { depends_on = [time_sleep.wait_for_minutes] - for_each = local.create_cw_metrics_source ? toset(var.cloudwatch_metrics_source_details.limit_to_namespaces) : [] + for_each = local.create_cw_metrics_source && length(local.aws_namespace) > 0 ? toset(local.aws_namespace) : [] source = "SumoLogic/sumo-logic-integrations/sumologic//aws/cloudwatchmetrics" create_collector = false diff --git a/aws-observability-terraform/source-module/outputs.tf b/aws-observability-terraform/source-module/outputs.tf index 3b2edc18..94e3eb49 100644 --- a/aws-observability-terraform/source-module/outputs.tf +++ b/aws-observability-terraform/source-module/outputs.tf @@ -79,12 +79,17 @@ output "classic_lb_auto_enable_stack" { } output "cloudwatch_metrics_source" { - value = local.create_cw_metrics_source ? toset([ - for namespace in var.cloudwatch_metrics_source_details.limit_to_namespaces : module.cloudwatch_metrics_source_module[namespace].sumologic_source + value = local.create_cw_metrics_source && length(local.aws_namespace) > 0 ? toset([ + for namespace in local.aws_namespace : module.cloudwatch_metrics_source_module[namespace].sumologic_source ]) : [] description = "Sumo Logic AWS CloudWatch Metrics source." } +output "cloudwatch_custom_metrics_source" { + value = local.create_cw_metrics_source && length(local.custom_namespace) > 0 ? module.cloudwatch_custom_metrics_source_module["Custom"].sumologic_source : null + description = "Sumo Logic CloudWatch Custom Metrics source." +} + output "kinesis_firehose_for_metrics_source" { value = local.create_kf_metrics_source ? module.kinesis_firehose_for_metrics_source_module["kinesis_firehose_for_metrics_source_module"].sumologic_source : null description = "Sumo Logic AWS Kinesis Firehose for Metrics source."