-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding a module for event-bridge-rule
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Create EventBridge event-bus - if required | ||
resource "aws_cloudwatch_event_bus" "custom_event_bus" { | ||
count = var.create_event_bus ? 1 : 0 | ||
name = var.event_bus_name | ||
} | ||
|
||
resource "aws_cloudwatch_event_rule" "event_rule" { | ||
name = var.event_rule_name | ||
description = var.event_rule_description | ||
event_bus_name = var.event_bus_name | ||
event_pattern = jsonencode({ | ||
source = var.event_sources | ||
}) | ||
depends_on = [aws_cloudwatch_event_bus.custom_event_bus] | ||
} | ||
|
||
resource "aws_cloudwatch_event_target" "event_target" { | ||
rule = aws_cloudwatch_event_rule.event_rule.name | ||
event_bus_name = var.event_bus_name | ||
arn = var.target_arn | ||
role_arn = aws_iam_role.eventbridge_role.arn | ||
} | ||
|
||
resource "aws_iam_role" "eventbridge_role" { | ||
name = var.role_name | ||
|
||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow" | ||
Principal = { Service = "events.amazonaws.com" } | ||
Action = "sts:AssumeRole" | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_iam_role_policy" "eventbridge_policy" { | ||
role = aws_iam_role.eventbridge_role.id | ||
|
||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow" | ||
Action = var.role_actions | ||
Resource = var.target_arn | ||
} | ||
] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
output "event_bus_arn" { | ||
description = "ARN of the created EventBridge Event-Bus" | ||
value = length(aws_cloudwatch_event_bus.custom_event_bus) > 0 ? aws_cloudwatch_event_bus.custom_event_bus[0].arn : null | ||
} | ||
|
||
output "event_rule_arn" { | ||
description = "ARN of the created EventBridge rule" | ||
value = aws_cloudwatch_event_rule.event_rule.arn | ||
} | ||
|
||
output "event_target_arn" { | ||
description = "ARN of the EventBridge target" | ||
value = aws_cloudwatch_event_target.event_target.arn | ||
} | ||
|
||
output "iam_role_arn" { | ||
description = "ARN of the IAM role used by EventBridge" | ||
value = aws_iam_role.eventbridge_role.arn | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
variable "create_event_bus" { | ||
type = bool | ||
description = "whether to create event-bus or not: true or false" | ||
} | ||
|
||
variable "event_rule_name" { | ||
description = "Name of the EventBridge rule" | ||
type = string | ||
} | ||
|
||
variable "event_rule_description" { | ||
description = "Description of the EventBridge rule" | ||
type = string | ||
} | ||
|
||
variable "event_bus_name" { | ||
description = "Event bus name where rule is created" | ||
type = string | ||
} | ||
|
||
variable "event_sources" { | ||
description = "Event sources to match in the event pattern" | ||
type = list(string) | ||
} | ||
|
||
variable "target_arn" { | ||
description = "ARN of the target for the event rule" | ||
type = string | ||
} | ||
|
||
variable "role_name" { | ||
description = "IAM Role name for EventBridge" | ||
type = string | ||
} | ||
|
||
variable "role_actions" { | ||
description = "List of actions the IAM Role should allow" | ||
type = list(string) | ||
} |