@@ -32,34 +32,62 @@ locals {
3232 health_event = {
3333 name = " HealthEvent"
3434 description = " AWS health event"
35- event_pattern = {
36- source = [" aws.health" ]
37- detail-type = [" AWS Health Event" ]
38- }
35+ event_pattern = merge (
36+ {
37+ source = [" aws.health" ]
38+ detail-type = [" AWS Health Event" ]
39+ },
40+ try (length (var. aws_node_termination_handler_asg_names ) > 0 ? {
41+ detail = {
42+ AutoScalingGroupName = var.aws_node_termination_handler_asg_names
43+ }
44+ } : {}, {})
45+ )
3946 }
4047 spot_interupt = {
4148 name = " SpotInterrupt"
4249 description = " EC2 spot instance interruption warning"
43- event_pattern = {
44- source = [" aws.ec2" ]
45- detail-type = [" EC2 Spot Instance Interruption Warning" ]
46- }
50+ event_pattern = merge (
51+ {
52+ source = [" aws.ec2" ]
53+ detail-type = [" EC2 Spot Instance Interruption Warning" ]
54+ },
55+ try (length (var. aws_node_termination_handler_asg_names ) > 0 ? {
56+ detail = {
57+ AutoScalingGroupName = var.aws_node_termination_handler_asg_names
58+ }
59+ } : {}, {})
60+ )
4761 }
4862 instance_rebalance = {
4963 name = " InstanceRebalance"
5064 description = " EC2 instance rebalance recommendation"
51- event_pattern = {
52- source = [" aws.ec2" ]
53- detail-type = [" EC2 Instance Rebalance Recommendation" ]
54- }
65+ event_pattern = merge (
66+ {
67+ source = [" aws.ec2" ]
68+ detail-type = [" EC2 Instance Rebalance Recommendation" ]
69+ },
70+ try (length (var. aws_node_termination_handler_asg_names ) > 0 ? {
71+ detail = {
72+ AutoScalingGroupName = var.aws_node_termination_handler_asg_names
73+ }
74+ } : {}, {})
75+ )
5576 }
5677 instance_state_change = {
5778 name = " InstanceStateChange"
5879 description = " EC2 instance state-change notification"
59- event_pattern = {
60- source = [" aws.ec2" ]
61- detail-type = [" EC2 Instance State-change Notification" ]
62- }
80+ event_pattern = merge (
81+ {
82+ source = [" aws.ec2" ]
83+ detail-type = [" EC2 Instance State-change Notification" ]
84+ },
85+ try (length (var. aws_node_termination_handler_asg_names ) > 0 ? {
86+ detail = {
87+ AutoScalingGroupName = var.aws_node_termination_handler_asg_names
88+ }
89+ } : {}, {})
90+ )
6391 }
6492 }
6593}
0 commit comments