-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
79 lines (66 loc) · 2.19 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
locals {
alert_groups_file = yamldecode(file("assets/exported_alert_rules.yaml"))
duration_multiplier = {
"s" = 1
"m" = 60
"h" = 60 * 60
"d" = 60 * 60 * 24
}
}
data "grafana_data_source" "prometheus" {
name = format("Prometheus@%s", var.cluster_name)
}
resource "grafana_folder" "introduction" {
title = "groundcover introduction"
}
resource "grafana_dashboard" "kubernetes_resources" {
folder = grafana_folder.introduction.id
config_json = file("assets/kubernetes_resource_dashboard.json")
}
resource "grafana_rule_group" "alertrule" {
for_each = {
for group in local.alert_groups_file.groups : group.name => group
}
name = each.value.name
folder_uid = grafana_folder.introduction.uid
org_id = data.grafana_data_source.prometheus.org_id
interval_seconds = sum(
[
for duration in regexall("([0-9]+)([a-z]+)", each.value.interval) : duration[0] * local.duration_multiplier[duration[1]]
]
)
dynamic "rule" {
for_each = each.value.rules
content {
for = rule.value.for
name = rule.value.title
is_paused = rule.value.isPaused
condition = rule.value.condition
no_data_state = rule.value.noDataState
exec_err_state = rule.value.execErrState
labels = try(rule.value.labels, null)
annotations = try(rule.value.annotations, null)
dynamic "data" {
iterator = rule_data
for_each = rule.value.data
content {
ref_id = rule_data.value.refId
datasource_uid = startswith(rule_data.value.datasourceUid, "__") ? rule_data.value.datasourceUid : data.grafana_data_source.prometheus.uid
model = jsonencode(
merge(rule_data.value.model,
{
datasource = {
uid = startswith(rule_data.value.datasourceUid, "__") ? rule_data.value.datasourceUid : data.grafana_data_source.prometheus.uid
}
}
)
)
relative_time_range {
to = try(rule_data.value.relativeTimeRange.to, 0)
from = try(rule_data.value.relativeTimeRange.from, 0)
}
}
}
}
}
}