-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathevent_rules.tf
100 lines (83 loc) · 2.91 KB
/
event_rules.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
resource "aws_cloudwatch_event_rule" "node_termination_handler_instance_terminate" {
name = format("%s-node-termination-handler-instance-terminate", var.cluster_name)
description = var.cluster_name
event_pattern = jsonencode({
source = ["aws.autoscaling"]
detail-type = [
"EC2 Instance-terminate Lifecycle Action"
]
})
}
resource "aws_cloudwatch_event_target" "node_termination_handler_instance_terminate" {
rule = aws_cloudwatch_event_rule.node_termination_handler_instance_terminate.name
target_id = "SendToSQS"
arn = aws_sqs_queue.main.arn
}
resource "aws_cloudwatch_event_rule" "node_termination_handler_scheduled_change" {
name = format("%s-node-termination-handler-scheduled-change", var.cluster_name)
description = var.cluster_name
event_pattern = jsonencode({
source = ["aws.health"]
detail-type = [
"AWS Health Event"
]
detail = {
service = [
"EC2"
]
eventTypeCategory = [
"scheduledChange"
]
}
})
}
resource "aws_cloudwatch_event_target" "node_termination_handler_scheduled_change" {
rule = aws_cloudwatch_event_rule.node_termination_handler_scheduled_change.name
target_id = "SendToSQS"
arn = aws_sqs_queue.main.arn
}
resource "aws_cloudwatch_event_rule" "node_termination_handler_spot_termination" {
name = format("%s-node-termination-handler-spot-termination", var.cluster_name)
description = var.cluster_name
event_pattern = jsonencode({
source = ["aws.ec2"]
detail-type = [
"EC2 Spot Instance Interruption Warning"
]
})
}
resource "aws_cloudwatch_event_target" "node_termination_handler_spot_termination" {
rule = aws_cloudwatch_event_rule.node_termination_handler_spot_termination.name
target_id = "SendToSQS"
arn = aws_sqs_queue.main.arn
}
resource "aws_cloudwatch_event_rule" "node_termination_handler_rebalance" {
name = format("%s-node-termination-handler-rebalance", var.cluster_name)
description = var.cluster_name
event_pattern = jsonencode({
source = ["aws.ec2"]
detail-type = [
"EC2 Instance Rebalance Recommendation"
]
})
}
resource "aws_cloudwatch_event_target" "node_termination_handler_rebalance" {
rule = aws_cloudwatch_event_rule.node_termination_handler_rebalance.name
target_id = "SendToSQS"
arn = aws_sqs_queue.main.arn
}
resource "aws_cloudwatch_event_rule" "node_termination_handler_state_change" {
name = format("%s-node-termination-handler-state-change", var.cluster_name)
description = var.cluster_name
event_pattern = jsonencode({
source = ["aws.ec2"]
detail-type = [
"EC2 Instance State-change Notification"
]
})
}
resource "aws_cloudwatch_event_target" "node_termination_handler_state_change" {
rule = aws_cloudwatch_event_rule.node_termination_handler_state_change.name
target_id = "SendToSQS"
arn = aws_sqs_queue.main.arn
}