From adbba9362dd08cb9564f0daaaaef4b97576d3be3 Mon Sep 17 00:00:00 2001 From: guyrenny <127672145+guyrenny@users.noreply.github.com> Date: Tue, 18 Feb 2025 09:56:07 +0200 Subject: [PATCH] feat: Add option to filter events by detail_type in eventbridge module (#209) * feat: add option to filter events by detail_type * feat: update changelog --- CHANGELOG.md | 5 +++ examples/eventbridge/variables.tf | 26 ++++++++++++++-- modules/eventbridge/README.md | 39 ++++++++++------------- modules/eventbridge/main.tf | 50 +++++++++++++----------------- modules/eventbridge/variables.tf | 13 +++++++- modules/locals_variables/locals.tf | 6 ++++ 6 files changed, 85 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df499bde..2595359b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v2.7.0 +#### **eventbridge** +### 🚀 New components 🚀 +- Add support to filter events by detail type + ## v2.6.1 #### **coralogix-aws-shipper** ### 🧰 Bug fixes 🧰 diff --git a/examples/eventbridge/variables.tf b/examples/eventbridge/variables.tf index 6d07e38a..a239ab8e 100644 --- a/examples/eventbridge/variables.tf +++ b/examples/eventbridge/variables.tf @@ -15,7 +15,18 @@ variable "private_key" { } variable "coralogix_region" { - description = "Coralogix account region: us, singapore, ireland, india, stockholm [in lower-case letters]" + description = "The Coralogix location region, possible options are [EU1, EU2, AP1, AP2, AP3, US1, US2]" + type = string + validation { + condition = contains(["EU1", "EU2", "AP1", "AP2", "AP3", "US1", "US2", "ireland", "india", "stockholm", "singapore", "us", "us2", "Custom"], var.coralogix_region) + error_message = "The coralogix region must be one of these values: [EU1, EU2, AP1, AP2, AP3, US1, US2, Custom]." + } +} + +variable "custom_url" { + description = "Custom coralogix url" + type = string + default = "" } variable "sources" { @@ -28,4 +39,15 @@ variable "application_name" { description = "Coralogix application name" type = string default = null -} \ No newline at end of file +} +variable "policy_name" { + description = "AWS IAM policy name" + type = string + default = "EventBridge_policy" +} + +variable "detail_type" { + description = "AWS eventbridge detail type" + type = list(string) + default = null +} diff --git a/modules/eventbridge/README.md b/modules/eventbridge/README.md index e528c050..964ece81 100644 --- a/modules/eventbridge/README.md +++ b/modules/eventbridge/README.md @@ -21,12 +21,14 @@ The application name by default is the eventbridge delivery stream name, but it ### Coralogix account region The coralogix region variable accepts one of the following regions: -* us -* singapore -* ireland -* india -* stockholm -* custom +* EU1 +* EU2 +* AP1 +* AP2 +* AP3 +* US1 +* US2 +* Custom *** All of the regions must be written with lower-case letters. @@ -34,12 +36,14 @@ The coralogix region variable accepts one of the following regions: | Region | Logs Endpoint |-----------|-----------------------------------------------------------------| -| us | `https://aws-events.coralogix.us/aws/event` | -| us2 | `https://aws-events.cx498.coralogix.com/aws/event` | -| singapore | `https://aws-events.coralogixsg.com/aws/event` | -| ireland | `https://aws-events.coralogix.com/aws/event` | -| india | `https://aws-events.coralogix.in/aws/event` | -| stockholm | `https://aws-events.eu2.coralogix.com/aws/event` | +| EU1 | `https://aws-events.coralogix.us/aws/event` | +| EU2 | `https://aws-events.eu2.coralogix.com/aws/event` | +| AP1 | `https://aws-events.coralogixsg.com/aws/event` | +| AP2 | `https://aws-events.coralogixsg.com/aws/event` | +| AP3 | `https://aws-events.ap3.coralogix.com/aws/event` | +| US1 | `https://aws-events.coralogix.us/aws/event` | +| US2 | `https://aws-events.cx498.coralogix.us/aws/event` | +| Custom | `https://aws-events./aws/event` | ## Requirements @@ -80,16 +84,7 @@ The coralogix region variable accepts one of the following regions: | [role\_name](#input\_role\_name) | The name of the eventbridge role | `string` | n/a | yes | | [sources](#input\_sources) | The services for which we will send events | `list(any)` |
[
"aws.ec2",
"aws.autoscaling",
"aws.cloudwatch",
"aws.events",
"aws.health",
"aws.rds"
]
| no | | [policy_name](#input\_custom\_url) | Custom aws_iam_policy | `string` | `EventBridge_policy` | no | - -## Coralgoix regions -| Coralogix region | AWS Region | Coralogix Domain | -|------|------------|------------| -| `Ireland` | `eu-west-1` | coralogix.com | -| `Stockholm` | `eu-north-1` | eu2.coralogix.com | -| `India` | `ap-south-1` | coralogix.in | -| `Singapore` | `ap-southeast-1` | coralogixsg.com | -| `US` | `us-east-2` | coralogix.us | -| `US2` | `us-west-2` | cx498.coralogix.com | +| [detail_type](#input\_detail\_type) | AWS eventbridge detail type for the rule to filter by | `list(string)` | `null` | no | ## Outputs diff --git a/modules/eventbridge/main.tf b/modules/eventbridge/main.tf index e1d2e17a..16e26dba 100644 --- a/modules/eventbridge/main.tf +++ b/modules/eventbridge/main.tf @@ -7,30 +7,15 @@ terraform { } } +module "locals" { + source = "../locals_variables" + + integration_type = "None" + random_string = "None" +} + locals { - endpoint_url = { - "us" = { - url = "https://aws-events.coralogix.us/aws/event" - } - "singapore" = { - url = "https://aws-events.coralogixsg.com/aws/event" - } - "ireland" = { - url = "https://aws-events.coralogix.com/aws/event" - } - "india" = { - url = "https://aws-events.coralogix.in/aws/event" - } - "stockholm" = { - url = "https://aws-events.eu2.coralogix.com/aws/event" - } - "us2" = { - url = "https://aws-events.cx498.coralogix.com/aws/event" - } - "custom" = { - url = "${var.custom_url}" - } - } + endpoint_url = "https://aws-events.${lookup(module.locals.coralogix_domains, var.coralogix_region, "EU1")}/aws/event" tags = { terraform-module = "eventbridge-to-coralogix" terraform-module-version = "v0.0.3" @@ -105,7 +90,7 @@ resource "aws_cloudwatch_event_connection" "event-connectiong" { resource "aws_cloudwatch_event_api_destination" "api-connection" { name = "toCoralogix" description = "EventBridge Api destination to Coralogix" - invocation_endpoint = local.endpoint_url[var.coralogix_region].url + invocation_endpoint = local.endpoint_url http_method = "POST" invocation_rate_limit_per_second = 300 connection_arn = aws_cloudwatch_event_connection.event-connectiong.arn @@ -113,18 +98,25 @@ resource "aws_cloudwatch_event_api_destination" "api-connection" { // Connecting between the rule and the api target resource "aws_cloudwatch_event_target" "my_event_target" { - arn = aws_cloudwatch_event_api_destination.api-connection.arn - rule = aws_cloudwatch_event_rule.eventbridge_rule.name - role_arn = aws_iam_role.eventbridge_role.arn + event_bus_name = var.eventbridge_stream + arn = aws_cloudwatch_event_api_destination.api-connection.arn + rule = aws_cloudwatch_event_rule.eventbridge_rule.name + role_arn = aws_iam_role.eventbridge_role.arn } // Creating Rule for classify the events we want to get resource "aws_cloudwatch_event_rule" "eventbridge_rule" { name = "eventbridge_rule" description = "Capture the main events" + event_bus_name = var.eventbridge_stream ///A number of services that we think are relevant to monitor, sub-alerts can be changed and classified - event_pattern = jsonencode( + event_pattern = var.detail_type != null ? jsonencode( { "source" : var.sources - }) + "detail-type" : var.detail_type + }): jsonencode( + { + "source" : var.sources + } + ) } diff --git a/modules/eventbridge/variables.tf b/modules/eventbridge/variables.tf index 74331be7..a239ab8e 100644 --- a/modules/eventbridge/variables.tf +++ b/modules/eventbridge/variables.tf @@ -15,7 +15,12 @@ variable "private_key" { } variable "coralogix_region" { - description = "Coralogix account region: us, us2, singapore, ireland, india, stockholm, custom [in lower-case letters]" + description = "The Coralogix location region, possible options are [EU1, EU2, AP1, AP2, AP3, US1, US2]" + type = string + validation { + condition = contains(["EU1", "EU2", "AP1", "AP2", "AP3", "US1", "US2", "ireland", "india", "stockholm", "singapore", "us", "us2", "Custom"], var.coralogix_region) + error_message = "The coralogix region must be one of these values: [EU1, EU2, AP1, AP2, AP3, US1, US2, Custom]." + } } variable "custom_url" { @@ -40,3 +45,9 @@ variable "policy_name" { type = string default = "EventBridge_policy" } + +variable "detail_type" { + description = "AWS eventbridge detail type" + type = list(string) + default = null +} diff --git a/modules/locals_variables/locals.tf b/modules/locals_variables/locals.tf index 42e880d5..4c5a8adb 100644 --- a/modules/locals_variables/locals.tf +++ b/modules/locals_variables/locals.tf @@ -14,15 +14,21 @@ locals { coralogix_domains = { Europe = "coralogix.com" EU1 = "coralogix.com" + ireland = "coralogix.com" Europe2 = "eu2.coralogix.com" + stockholm = "eu2.coralogix.com" EU2 = "eu2.coralogix.com" India = "coralogix.in" + india = "coralogix.in" AP1 = "coralogix.in" Singapore = "coralogixsg.com" + singapore = "coralogixsg.com" AP2 = "coralogixsg.com" US = "coralogix.us" + us = "coralogix.us" US1 = "coralogix.us" US2 = "cx498.coralogix.com" + us2 = "cx498.coralogix.com" AP3 = "ap3.coralogix.com" }