forked from cloudposse/terraform-datadog-platform
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
50 lines (43 loc) · 2.46 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
locals {
enabled = module.this.enabled
alert_tags = local.enabled && var.alert_tags != null ? format("%s%s", var.alert_tags_separator, join(var.alert_tags_separator, var.alert_tags)) : ""
}
# https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/monitor
resource "datadog_monitor" "default" {
for_each = local.enabled ? var.datadog_monitors : {}
name = each.value.name
type = each.value.type
query = each.value.query
message = format("%s%s", each.value.message, local.alert_tags)
escalation_message = lookup(each.value, "escalation_message", null)
require_full_window = lookup(each.value, "require_full_window", null)
notify_no_data = lookup(each.value, "notify_no_data", null)
new_host_delay = lookup(each.value, "new_host_delay", null)
evaluation_delay = lookup(each.value, "evaluation_delay", null)
no_data_timeframe = lookup(each.value, "no_data_timeframe", null)
renotify_interval = lookup(each.value, "renotify_interval", null)
notify_audit = lookup(each.value, "notify_audit", null)
timeout_h = lookup(each.value, "timeout_h", null)
include_tags = lookup(each.value, "include_tags", null)
enable_logs_sample = lookup(each.value, "enable_logs_sample", null)
force_delete = lookup(each.value, "force_delete", null)
monitor_thresholds {
warning = lookup(each.value.thresholds, "warning", null)
warning_recovery = lookup(each.value.thresholds, "warning_recovery", null)
critical = lookup(each.value.thresholds, "critical", null)
critical_recovery = lookup(each.value.thresholds, "critical_recovery", null)
ok = lookup(each.value.thresholds, "ok", null)
unknown = lookup(each.value.thresholds, "unknown", null)
}
monitor_threshold_windows {
recovery_window = lookup(each.value.threshold_windows, "recovery_window", null)
trigger_window = lookup(each.value.threshold_windows, "trigger_window", null)
}
# Assign restricted roles
# Only these roles will have access to the monitor according to their permissions
restricted_roles = try(var.restricted_roles_map[each.key], null)
# `restricted_roles` conflicts with `locked`
# Use `locked`` only if `restricted_roles` is not provided
locked = try(var.restricted_roles_map[each.key], null) == null ? lookup(each.value, "locked", null) : null
tags = lookup(each.value, "tags", module.this.tags)
}