-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.tf
211 lines (200 loc) · 10.1 KB
/
main.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
locals {
# Logs Monitor
LogsCriticalAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="Critical" && var.monitor_monitor_type == "Logs"] : []
LogsResolveCriticalAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="ResolvedCritical" && var.monitor_monitor_type == "Logs"] : []
LogsWarningAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="Warning" && var.monitor_monitor_type == "Logs"] : []
LogsResolveWarningAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="ResolvedWarning" && var.monitor_monitor_type == "Logs"] : []
LogsMissingData = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="MissingData" && var.monitor_monitor_type == "Logs"] : []
# Metrics Monitor
MetricsCriticalAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="Critical" && var.monitor_monitor_type == "Metrics"] : []
MetricsResolveCriticalAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="ResolvedCritical" && var.monitor_monitor_type == "Metrics"] : []
MetricsWarningAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="Warning" && var.monitor_monitor_type == "Metrics"] : []
MetricsResolveWarningAlert = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="ResolvedWarning" && var.monitor_monitor_type == "Metrics"] : []
MetricsMissingData = var.triggers != null ? [for d in var.triggers: d if d.trigger_type =="MissingData" && var.monitor_monitor_type == "Metrics"] : []
# SLO SLI Monitor
SLOSLICriticalAlert = var.slo_sli_triggers != null ? [for d in var.slo_sli_triggers: d if d.trigger_type =="Critical" && var.monitor_monitor_type == "Slo"] : []
SLOSLIWarningAlert = var.slo_sli_triggers != null ? [for d in var.slo_sli_triggers: d if d.trigger_type =="Warning" && var.monitor_monitor_type == "Slo"] : []
# SLO Burn Rate Monitor
SLOBurnRateCriticalAlert = var.slo_burnrate_triggers != null ? [for d in var.slo_burnrate_triggers: d if d.trigger_type =="Critical" && var.monitor_monitor_type == "Slo"] : []
SLOBurnRateWarningAlert = var.slo_burnrate_triggers != null ? [for d in var.slo_burnrate_triggers: d if d.trigger_type =="Warning" && var.monitor_monitor_type == "Slo"] : []
hasLogsCriticalAlert = (length(local.LogsCriticalAlert) + length(local.LogsResolveCriticalAlert)) == 2
hasLogsWarningAlert = (length(local.LogsWarningAlert) + length(local.LogsResolveWarningAlert)) == 2
hasMetricsCriticalAlert = (length(local.MetricsCriticalAlert) + length(local.MetricsResolveCriticalAlert)) == 2
hasMetricsWarningAlert = (length(local.MetricsWarningAlert)+ length(local.MetricsResolveWarningAlert)) == 2
hasLogsMissingData = length(local.LogsMissingData) == 1
hasMetricsMissingData = length(local.MetricsMissingData) == 1
hasSLOSLICriticalAlert = length(local.SLOSLICriticalAlert) == 1
hasSLOSLIWarningAlert = length(local.SLOSLIWarningAlert) == 1
hasSLOBurnRateCriticalAlert = length(local.SLOBurnRateCriticalAlert) == 1
hasSLOBurnRateWarningAlert = length(local.SLOBurnRateWarningAlert) == 1
}
resource "sumologic_monitor" "tf_monitor" {
name = var.monitor_name
parent_id = var.monitor_parent_id
description = var.monitor_description
type = "MonitorsLibraryMonitor"
is_disabled = var.monitor_is_disabled
content_type = "Monitor"
monitor_type = var.monitor_monitor_type
group_notifications = var.group_notifications
slo_id = var.monitor_slo_id
evaluation_delay = var.monitor_evaluation_delay
dynamic "queries" {
for_each = var.queries == null ? {} : var.queries
content {
row_id = queries.key
query = queries.value
}
}
trigger_conditions {
dynamic "logs_static_condition" {
for_each = toset(var.monitor_monitor_type == "Logs" && (local.hasLogsCriticalAlert||local.hasLogsWarningAlert) ? ["1"] : [])
content {
dynamic "critical" {
for_each = local.hasLogsCriticalAlert ? ["1"] : []
content {
time_range = local.LogsCriticalAlert[0].time_range
alert {
threshold = local.LogsCriticalAlert[0].threshold
threshold_type = local.LogsCriticalAlert[0].threshold_type
}
resolution {
threshold = local.LogsResolveCriticalAlert[0].threshold
threshold_type = local.LogsResolveCriticalAlert[0].threshold_type
}
}
}
dynamic "warning" {
for_each = local.hasLogsWarningAlert ? ["1"] : []
content {
time_range = local.LogsWarningAlert[0].time_range
alert {
threshold = local.LogsWarningAlert[0].threshold
threshold_type = local.LogsWarningAlert[0].threshold_type
}
resolution {
threshold = local.LogsResolveWarningAlert[0].threshold
threshold_type = local.LogsResolveWarningAlert[0].threshold_type
}
}
}
}
}
dynamic "logs_missing_data_condition" {
for_each = local.hasLogsMissingData ? ["1"] : []
content {
time_range = local.LogsMissingData[0].time_range
}
}
dynamic "metrics_static_condition" {
for_each = toset(var.monitor_monitor_type == "Metrics"&&(local.hasMetricsCriticalAlert||local.hasMetricsWarningAlert) ? ["1"] : [])
content {
dynamic "critical" {
for_each = local.hasMetricsCriticalAlert ? ["1"] : []
content {
time_range = local.MetricsCriticalAlert[0].time_range
occurrence_type = local.MetricsCriticalAlert[0].occurrence_type
alert {
threshold = local.MetricsCriticalAlert[0].threshold
threshold_type = local.MetricsCriticalAlert[0].threshold_type
}
resolution {
threshold = local.MetricsResolveCriticalAlert[0].threshold
threshold_type = local.MetricsResolveCriticalAlert[0].threshold_type
}
}
}
dynamic "warning" {
for_each = local.hasMetricsWarningAlert ? ["1"] : []
content {
time_range = local.MetricsWarningAlert[0].time_range
occurrence_type = local.MetricsWarningAlert[0].occurrence_type
alert {
threshold = local.MetricsWarningAlert[0].threshold
threshold_type = local.MetricsWarningAlert[0].threshold_type
}
resolution {
threshold = local.MetricsResolveWarningAlert[0].threshold
threshold_type = local.MetricsResolveWarningAlert[0].threshold_type
}
}
}
}
}
dynamic "metrics_missing_data_condition" {
for_each = local.hasMetricsMissingData ? ["1"] : []
content {
time_range = local.MetricsMissingData[0].time_range
trigger_source = local.MetricsMissingData[0].trigger_source
}
}
dynamic "slo_sli_condition" {
for_each = toset(var.monitor_monitor_type == "Slo" && var.monitor_slo_type == "Sli" ? ["1"] : [])
content {
dynamic "critical" {
for_each = local.hasSLOSLICriticalAlert ? ["1"] : []
content {
sli_threshold = local.SLOSLICriticalAlert[0].threshold
}
}
dynamic "warning" {
for_each = local.hasSLOSLIWarningAlert ? ["1"] : []
content {
sli_threshold = local.SLOSLIWarningAlert[0].threshold
}
}
}
}
dynamic "slo_burn_rate_condition" {
for_each = toset(var.monitor_monitor_type == "Slo" && var.monitor_slo_type == "BurnRate" ? ["1"] : [])
content {
dynamic "critical" {
for_each = local.hasSLOBurnRateCriticalAlert ? ["1"] : []
content {
time_range = local.SLOBurnRateCriticalAlert[0].time_range
burn_rate_threshold = local.SLOBurnRateCriticalAlert[0].threshold
}
}
dynamic "warning" {
for_each = local.hasSLOBurnRateWarningAlert ? ["1"] : []
content {
time_range = local.SLOBurnRateWarningAlert[0].time_range
burn_rate_threshold = local.SLOBurnRateWarningAlert[0].threshold
}
}
}
}
}
dynamic "obj_permission" {
for_each = var.monitor_permission
content {
subject_type = obj_permission.value.subject_type
subject_id = obj_permission.value.subject_id
permissions = obj_permission.value.permissions
}
}
dynamic "notifications" {
for_each = var.connection_notifications
content {
run_for_trigger_types = notifications.value.run_for_trigger_types
notification {
connection_type = notifications.value.connection_type
connection_id = notifications.value.connection_id
payload_override = notifications.value.payload_override
}
}
}
dynamic "notifications" {
for_each = var.email_notifications
content {
run_for_trigger_types = notifications.value.run_for_trigger_types
notification {
connection_type = notifications.value.connection_type
recipients = notifications.value.recipients
subject = notifications.value.subject
time_zone = notifications.value.time_zone
message_body = notifications.value.message_body
}
}
}
}