forked from kabisa/terraform-datadog-generic-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
92 lines (80 loc) · 2.37 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
locals {
notification_channel = var.alerting_enabled ? var.notification_channel : ""
tag_specials_regex = "/[^a-z0-9\\-_:.\\/]/"
tags = concat(
[
"terraform:true",
"env:${var.env}",
"service:${var.service}",
],
var.additional_tags
)
# Normalize all the tags according to best practices defined by Datadog. The
# following changes are made:
#
# * Make all characters lowercase.
# * Replace special characters with an underscore.
# * Remove duplicate underscores.
# * Remove any non-letter leading characters.
# * Remove any trailing underscores.
#
# See: https://docs.datadoghq.com/developers/guide/what-best-practices-are-recommended-for-naming-metrics-and-tags
normalized_tags = [
for tag
in local.tags :
replace(
replace(
replace(
replace(lower(tag), local.tag_specials_regex, "_")
,
"/_+/",
"_"
),
"/^[^a-z]+/",
""
),
"/_+$/",
""
)
]
service_display_name = var.service_display_name != null ? var.service_display_name : var.service
}
resource "datadog_monitor" "generic_datadog_monitor" {
count = var.enabled ? 1 : 0
name = join(" - ", compact([
var.name_prefix,
local.service_display_name,
var.name,
var.name_suffix
]))
type = var.type
query = var.query
message = templatefile("${path.module}/alert.tpl", {
alert_message = var.alert_message
recovery_message = var.recovery_message
no_data_message = var.no_data_message
note = var.note
docs = var.docs
custom_message = var.custom_message
notification_channel = local.notification_channel
})
tags = local.normalized_tags
priority = var.priority
no_data_timeframe = var.no_data_timeframe
notify_no_data = var.notify_no_data
timeout_h = var.auto_resolve_time_h
require_full_window = var.require_full_window
new_group_delay = var.new_group_delay
monitor_thresholds {
critical = var.critical_threshold
critical_recovery = var.critical_recovery
warning = var.warning_threshold
warning_recovery = var.warning_recovery
ok = var.ok_threshold
}
monitor_threshold_windows {
recovery_window = var.anomaly_recovery_window
trigger_window = var.anomaly_trigger_window
}
restricted_roles = var.restricted_roles
}