-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path63-events-nth.tf
116 lines (95 loc) · 2.47 KB
/
63-events-nth.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# cloudwatch events
# EC2 Spot Instance Interruption Warning
resource "aws_cloudwatch_event_rule" "nth_spot" {
count = var.enable_event ? 1 : 0
name = format("%s-spot-interruption", local.sqs_nth)
description = "EC2 Spot Instance Interruption Warning"
event_pattern = jsonencode(
{
"source" : [
"aws.ec2"
]
"detail-type" : [
"EC2 Spot Instance Interruption Warning"
]
"detail" : {
"instance-action": [ "terminate" ]
}
}
)
tags = merge(
local.tags,
{
"Name" = format("%s-spot-interruption", local.sqs_nth)
},
)
}
resource "aws_cloudwatch_event_target" "nth_spot" {
count = var.enable_event ? 1 : 0
target_id = format("%s-spot-interruption", local.sqs_nth)
rule = aws_cloudwatch_event_rule.nth_spot.0.name
arn = aws_sqs_queue.nth.arn
}
# EC2 Instance State-change Notification
resource "aws_cloudwatch_event_rule" "nth_state" {
count = var.enable_event ? 1 : 0
name = format("%s-state-change", local.sqs_nth)
description = "EC2 Instance State-change Notification"
event_pattern = jsonencode(
{
"source" : [
"aws.ec2"
]
"detail-type" : [
"EC2 Instance State-change Notification"
]
"detail": {
"state": [ "shutting-down" ]
}
}
)
tags = merge(
local.tags,
{
"Name" = format("%s-state-change", local.sqs_nth)
},
)
}
resource "aws_cloudwatch_event_target" "nth_state" {
count = var.enable_event ? 1 : 0
target_id = format("%s-state-change", local.sqs_nth)
rule = aws_cloudwatch_event_rule.nth_state.0.name
arn = aws_sqs_queue.nth.arn
}
# AWS Health Event
resource "aws_cloudwatch_event_rule" "nth_scheduled" {
count = var.enable_event ? 1 : 0
name = format("%s-scheduled-change", local.sqs_nth)
description = "AWS Health Event"
event_pattern = jsonencode(
{
"source" : [
"aws.health"
]
"detail-type" : [
"AWS Health Event"
]
"detail": {
"service": [ "EC2" ]
"eventTypeCategory": [ "scheduledChange" ]
}
}
)
tags = merge(
local.tags,
{
"Name" = format("%s-scheduled-change", local.sqs_nth)
},
)
}
resource "aws_cloudwatch_event_target" "nth_scheduled" {
count = var.enable_event ? 1 : 0
target_id = format("%s-scheduled-change", local.sqs_nth)
rule = aws_cloudwatch_event_rule.nth_scheduled.0.name
arn = aws_sqs_queue.nth.arn
}