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

Added support for AWS tag filters in TF #214

Merged
merged 2 commits into from
Dec 3, 2024
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
2 changes: 2 additions & 0 deletions aws-observability-terraform/source-module/local.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ""
Expand Down
32 changes: 31 additions & 1 deletion aws-observability-terraform/source-module/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -165,6 +193,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
Expand All @@ -191,6 +220,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 = {
Expand Down
9 changes: 7 additions & 2 deletions aws-observability-terraform/source-module/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
6 changes: 6 additions & 0 deletions aws-observability-terraform/source-module/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading