-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
142 lines (112 loc) · 4 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
resource "pagerduty_business_service" "default" {
count = var.business ? 1 : 0
name = var.name
description = var.description
point_of_contact = var.point_of_contact
team = var.team_id
}
resource "pagerduty_service" "default" {
count = var.business ? 0 : 1
name = var.name
description = var.description
escalation_policy = var.escalation_policy_id
auto_resolve_timeout = var.auto_resolve_timeout
acknowledgement_timeout = var.acknowledgement_timeout
auto_pause_notifications_parameters {
enabled = var.auto_pause_notifications_parameters.enabled
timeout = var.auto_pause_notifications_parameters.timeout
}
dynamic "support_hours" {
for_each = var.support_hours != null ? [var.support_hours] : []
content {
type = support_hours.value.type
start_time = support_hours.value.start_time
end_time = support_hours.value.end_time
time_zone = support_hours.value.time_zone
days_of_week = support_hours.value.days_of_week
}
}
dynamic "incident_urgency_rule" {
for_each = var.incident_urgency_rule != null ? [var.incident_urgency_rule] : []
content {
type = incident_urgency_rule.value.type
urgency = incident_urgency_rule.value.urgency
dynamic "during_support_hours" {
for_each = incident_urgency_rule.value.during_support_hours != null ? [incident_urgency_rule.value.during_support_hours] : []
content {
type = during_support_hours.value.type
urgency = during_support_hours.value.urgency
}
}
dynamic "outside_support_hours" {
for_each = incident_urgency_rule.value.outside_support_hours != null ? [incident_urgency_rule.value.outside_support_hours] : []
content {
type = outside_support_hours.value.type
urgency = outside_support_hours.value.urgency
}
}
}
}
dynamic "scheduled_actions" {
for_each = var.scheduled_actions != null ? [var.scheduled_actions] : []
content {
type = scheduled_actions.value.type
to_urgency = scheduled_actions.value.to_urgency
at {
type = scheduled_actions.value.at.type
name = scheduled_actions.value.at.name
}
}
}
}
resource "pagerduty_alert_grouping_setting" "default" {
count = !var.business && var.alert_grouping_setting != null ? 1 : 0
services = [pagerduty_service.default[0].id]
name = "Managed by Terraform"
description = "Managed by Terraform"
type = var.alert_grouping_setting.type
config {
time_window = var.alert_grouping_setting.config.time_window
aggregate = var.alert_grouping_setting.config.aggregate
fields = var.alert_grouping_setting.config.fields
}
}
resource "pagerduty_service_dependency" "dependent" {
for_each = { for service in var.service_graph.dependent_services : service.name => service }
dependency {
dependent_service {
type = pagerduty_service.default[0].type
id = pagerduty_service.default[0].id
}
supporting_service {
type = each.value.type
id = each.value.id
}
}
}
resource "pagerduty_service_dependency" "supporting" {
for_each = { for service in var.service_graph.supporting_services : service.name => service }
dependency {
dependent_service {
type = each.value.type
id = each.value.id
}
supporting_service {
type = pagerduty_service.default[0].type
id = pagerduty_service.default[0].id
}
}
}
resource "pagerduty_slack_connection" "default" {
count = var.slack_connection != null ? 1 : 0
source_type = "service_reference"
source_id = pagerduty_service.default[0].id
workspace_id = var.slack_connection.workspace_id
channel_id = var.slack_connection.channel_id
notification_type = var.slack_connection.notification_type
config {
events = var.slack_connection.events
urgency = var.slack_connection.urgency
priorities = var.slack_connection.priorities
}
}