Skip to content

Commit

Permalink
include additional attrs for managing eventbridge rules
Browse files Browse the repository at this point in the history
  • Loading branch information
johnricords committed Jul 22, 2024
1 parent 2573322 commit 6f7ae3a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.0
current_version = 2.2.0
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_event_rule"></a> [event\_rule](#input\_event\_rule) | Object of input configs for the CloudWatch Event Rule | <pre>object({<br> name = string<br> description = optional(string)<br> event_pattern = optional(string)<br> event_bus_name = optional(string)<br><br> event_targets = optional(list(object({<br> name = string<br> arn = string<br><br> event_bus_name = optional(string)<br> role_arn = optional(string)<br> target_id = optional(string)<br><br> dead_letter_config = optional(object({<br> arn = string<br> }))<br><br> input_transformer = optional(object({<br> input_paths = optional(map(string))<br> input_template = string<br> }))<br><br> sqs_target = optional(object({<br> message_group_id = string<br> }))<br><br> })), [])<br> })</pre> | n/a | yes |
| <a name="input_event_rule"></a> [event\_rule](#input\_event\_rule) | Object of input configs for the CloudWatch Event Rule | <pre>object({<br> name = string<br> description = optional(string)<br> event_pattern = optional(string)<br> event_bus_name = optional(string, "default")<br> schedule_expression = optional(string)<br> state = optional(string)<br><br> event_targets = optional(list(object({<br> name = string<br> arn = string<br><br> event_bus_name = optional(string)<br> role_arn = optional(string)<br> target_id = optional(string)<br><br> dead_letter_config = optional(object({<br> arn = string<br> }))<br><br> input_transformer = optional(object({<br> input_paths = optional(map(string))<br> input_template = string<br> }))<br><br> sqs_target = optional(object({<br> message_group_id = string<br> }))<br><br> retry_policy = optional(object({<br> maximum_event_age_in_seconds = optional(string)<br> maximum_retry_attempts = optional(string)<br> }))<br><br> })), [])<br> })</pre> | n/a | yes |

## Outputs

Expand Down
19 changes: 15 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
resource "aws_cloudwatch_event_rule" "this" {

name = var.event_rule.name
description = var.event_rule.description
event_pattern = var.event_rule.event_pattern
event_bus_name = var.event_rule.event_bus_name
name = var.event_rule.name
description = var.event_rule.description
event_pattern = var.event_rule.event_pattern
event_bus_name = var.event_rule.event_bus_name
schedule_expression = var.event_rule.schedule_expression
state = var.event_rule.state
}

resource "aws_cloudwatch_event_target" "this" {
Expand Down Expand Up @@ -37,4 +39,13 @@ resource "aws_cloudwatch_event_target" "this" {
message_group_id = sqs_target.value.message_group_id
}
}

dynamic "retry_policy" {
for_each = each.value.retry_policy != null ? [each.value.retry_policy] : []
content {
maximum_event_age_in_seconds = retry_policy.value.maximum_event_age_in_seconds
maximum_retry_attempts = retry_policy.value.maximum_retry_attempts

}
}
}
10 changes: 8 additions & 2 deletions tests/create_all_any/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ data "aws_partition" "current" {}
locals {
event_rules = [
{
name = "event1"
description = random_string.this.result
name = "event1"
description = random_string.this.result
schedule_expression = "rate(5 minutes)"
event_bus_name = "default"
state = "ENABLED"
event_pattern = jsonencode({
source = ["aws.codecommit"],
detail-type = ["${random_string.this.result}"],
Expand Down Expand Up @@ -100,6 +103,9 @@ locals {
sqs_target = {
message_group_id = "${random_string.this.result}"
}
retry_policy = {
maximum_retry_attempts = 10
}
}
]
},
Expand Down
19 changes: 15 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
variable "event_rule" {
description = "Object of input configs for the CloudWatch Event Rule"
type = object({
name = string
description = optional(string)
event_pattern = optional(string)
event_bus_name = optional(string)
name = string
description = optional(string)
event_pattern = optional(string)
event_bus_name = optional(string, "default")
schedule_expression = optional(string)
state = optional(string)

event_targets = optional(list(object({
name = string
Expand All @@ -27,6 +29,15 @@ variable "event_rule" {
message_group_id = string
}))

retry_policy = optional(object({
maximum_event_age_in_seconds = optional(string)
maximum_retry_attempts = optional(string)
}))

})), [])
})
validation {
condition = var.event_rule.schedule_expression != null && var.event_rule.event_bus_name != "default"
error_message = "Scheduled expressions cannot be used on custom event buses"
}
}

0 comments on commit 6f7ae3a

Please sign in to comment.