Skip to content

Commit

Permalink
feat: Add option to filter events by detail_type in eventbridge module (
Browse files Browse the repository at this point in the history
#209)

* feat: add option to filter events by detail_type

* feat: update changelog
  • Loading branch information
guyrenny authored Feb 18, 2025
1 parent 0e0c0f5 commit adbba93
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 54 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 🧰
Expand Down
26 changes: 24 additions & 2 deletions examples/eventbridge/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -28,4 +39,15 @@ variable "application_name" {
description = "Coralogix application name"
type = string
default = null
}
}
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
}
39 changes: 17 additions & 22 deletions modules/eventbridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,29 @@ 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.

### Endpoints

| 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.<custom_domain>/aws/event` |


## Requirements
Expand Down Expand Up @@ -80,16 +84,7 @@ The coralogix region variable accepts one of the following regions:
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | The name of the eventbridge role | `string` | n/a | yes |
| <a name="input_sources"></a> [sources](#input\_sources) | The services for which we will send events | `list(any)` | <pre>[<br> "aws.ec2",<br> "aws.autoscaling",<br> "aws.cloudwatch",<br> "aws.events",<br> "aws.health",<br> "aws.rds"<br>]</pre> | no |
| <a name="input_policy_name"></a> [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 |
| <a name="input_detail_type"></a> [detail_type](#input\_detail\_type) | AWS eventbridge detail type for the rule to filter by | `list(string)` | `null` | no |

## Outputs

Expand Down
50 changes: 21 additions & 29 deletions modules/eventbridge/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -105,26 +90,33 @@ 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
}

// 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
}
)
}
13 changes: 12 additions & 1 deletion modules/eventbridge/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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
}
6 changes: 6 additions & 0 deletions modules/locals_variables/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down

0 comments on commit adbba93

Please sign in to comment.