forked from moneyforwardvietnam/terraform-datadog-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_slo.tf
54 lines (43 loc) · 1.76 KB
/
monitor_slo.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
locals {
datadog_monitor_slos = { for slo in var.datadog_slos : slo.name => slo if slo.type == "monitor" && lookup(slo, "enabled", true) && local.enabled }
}
module "datadog_monitors" {
source = "../monitors"
for_each = local.datadog_monitor_slos
datadog_monitors = lookup(each.value, "monitors", {})
alert_tags = var.alert_tags
alert_tags_separator = var.alert_tags_separator
context = module.this.context
}
resource "datadog_service_level_objective" "monitor_slo" {
for_each = local.datadog_monitor_slos
# Required
name = each.value.name
type = each.value.type
dynamic "thresholds" {
for_each = each.value.thresholds
content {
target = lookup(thresholds.value, "target", "99.00")
timeframe = lookup(thresholds.value, "timeframe", "7d")
warning = lookup(thresholds.value, "warning", "99.95")
}
}
groups = lookup(each.value, "groups", [])
# Either `monitor_ids` or `monitors` should be provided
# If `monitors` map is provided, the monitors are created in the `datadog_monitors` module
monitor_ids = try(each.value.monitor_ids, null) != null ? each.value.monitor_ids : module.datadog_monitors[each.key].datadog_monitor_ids
# Optional
description = lookup(each.value, "description", null)
force_delete = lookup(each.value, "force_delete", true)
validate = lookup(each.value, "validate", false)
# Convert terraform tags map to Datadog tags map
# If a key is supplied with a value, it will render "key:value" as a tag
# tags:
# key: value
# If a key is supplied without a value (null), it will render "key" as a tag
# tags:
# key: null
tags = [
for tagk, tagv in lookup(each.value, "tags", module.this.tags) : (tagv != null ? format("%s:%s", tagk, tagv) : tagk)
]
}