feat: Configurable event patterns for NTH EventBridge rules for all ec2 events#456
Merged
askulkarni2 merged 1 commit intoaws-ia:mainfrom Jul 24, 2025
Conversation
|
@JaseKoonce , thanks for your work here! I created the custom fix to solve that issue before you've provided these and previous PRs. Just a suggestion: should we once define the fix in the aws_cloudwatch_event_rule.aws_node_termination_handler instead of propagating it for each ec2_event? beforeresource "aws_cloudwatch_event_rule" "aws_node_termination_handler" {
for_each = { for k, v in local.aws_node_termination_handler_events : k => v if var.enable_aws_node_termination_handler }
name_prefix = "NTH-${each.value.name}-"
description = each.value.description
event_pattern = jsonencode(each.value.event_pattern)
tags = merge(
{ "ClusterName" : var.cluster_name },
var.tags,
)
}Afterresource "aws_cloudwatch_event_rule" "aws_node_termination_handler" {
for_each = { for k, v in local.aws_node_termination_handler_events : k => v if var.enable_aws_node_termination_handler }
name_prefix = "NTH-${each.value.name}-"
description = each.value.description
event_pattern = jsonencode(merge(each.value.event_pattern,
try(length(var.aws_node_termination_handler_asg_names)) > 0 ? {
detail = {
AutoScalingGroupName = var.aws_node_termination_handler_asg_names
}
} : {}))
tags = merge(
{ "ClusterName" : var.cluster_name },
var.tags,
)
} |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expands on work done in #454
What does this PR do?
In PR #454 a variable was added to allow the end user to create a pattern on their
EC2 Instance-terminate Lifecycle Actioneventbridge rule that is scoped to only their desired ASG. Without this, your event rules will receive and send events for every ASG in your account. Expanding on this work, I am re-using the ASG name variable to add patterns to the rest of the ec2 events.Motivation
More
pre-commit run -awith this PRFor Moderators
Additional Notes
plan output:




