-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
180 lines (167 loc) · 5.53 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
terraform {
required_providers {
pagerduty = {
source = "PagerDuty/pagerduty"
version = "3.1.1"
}
}
}
provider "pagerduty" {
token = var.token
user_token = var.pagerduty_user_token
}
data "pagerduty_escalation_policy" "this" {
name = var.escalation_policy
}
resource "pagerduty_service" "this" {
name = var.name
description = var.description
auto_resolve_timeout = var.resolve_timeout
acknowledgement_timeout = var.ack_timeout
escalation_policy = data.pagerduty_escalation_policy.this.id
alert_creation = var.alert_creation
dynamic "incident_urgency_rule" {
for_each = 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
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
content {
type = outside_support_hours.value["type"]
urgency = outside_support_hours.value["urgency"]
}
}
}
}
dynamic "alert_grouping_parameters" {
for_each = var.alert_grouping_parameters
content {
type = alert_grouping_parameters.value["type"]
dynamic "config" {
for_each = alert_grouping_parameters.value.config
content {
timeout = each.value.timeout
aggregate = each.value.aggregate
fields = each.value.fields
}
}
}
}
dynamic "auto_pause_notifications_parameters" {
for_each = var.auto_pause_notifications_parameters
content {
enabled = auto_pause_notifications_parameters.value["enabled"]
timeout = auto_pause_notifications_parameters.value["timeout"]
}
}
dynamic "support_hours" {
for_each = 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 "scheduled_actions" {
for_each = var.scheduled_actions
content {
to_urgency = scheduled_actions.value["to_urgency"]
type = scheduled_actions.value["type"]
dynamic "at" {
for_each = scheduled_actions.value.at
content {
name = at.value["name"]
type = at.value["type"]
}
}
}
}
}
data "pagerduty_vendor" "this" {
name = var.vendor_name
}
resource "pagerduty_service_integration" "this" {
count = var.enable_service_integration ? 1 : 0
name = data.pagerduty_vendor.this.name
vendor = data.pagerduty_vendor.this.id
service = pagerduty_service.this.id
# type = (do not use for Datadog or Cloudwatch "vendor" integrations..only for generic service integrations)
}
resource "aws_sns_topic" "this" {
count = var.create_sns_topic ? 1 : 0
name = var.service_name
}
resource "aws_sns_topic_subscription" "this" {
count = var.create_sns_topic ? 1 : 0
topic_arn = aws_sns_topic.this[0].arn
protocol = "https"
endpoint_auto_confirms = true #required or the subscription won't auto-confirm
endpoint = "https://events.pagerduty.com/integration/${pagerduty_service_integration.this[0].integration_key}/enqueue"
}
data "pagerduty_extension_schema" "this" {
count = var.create_extension ? 1 : 0
name = var.schema_name
}
resource "pagerduty_extension" "this" {
count = var.create_extension ? 1 : 0
name = var.extension_name
endpoint_url = var.endpoint_url
extension_schema = data.pagerduty_extension_schema.this[count.index].id
extension_objects = [pagerduty_service.this.id]
config = var.config
}
resource "pagerduty_maintenance_window" "this" {
for_each = {
for k, v in var.maintenance_windows : k => v if var.enable_maintenance_windows == true
}
start_time = each.value.start_time
end_time = each.value.end_time
description = each.value.description
services = [pagerduty_service.this.id]
}
resource "pagerduty_slack_connection" "this" {
for_each = {
for type in var.slack_connections : type.source_type => {
source_id = type.source_type == "service_reference" ? pagerduty_service.this.id : type.source_id
source_type = type.source_type
workspace_id = type.workspace_id
channel_id = type.channel_id
notification_type = type.notification_type
config = type.config
}
if var.create_slack_connection == true
}
source_id = each.value.source_id
source_type = each.value.source_type
workspace_id = each.value.workspace_id
channel_id = each.value.channel_id
notification_type = each.value.notification_type
dynamic "config" {
for_each = each.value.config
content {
events = config.value.events
priorities = config.value.priorities
urgency = config.value.urgency
}
}
}
data "pagerduty_vendor" "datadog" {
count = var.datadog_integration ? 1 : 0
name = "Datadog"
}
resource "pagerduty_service_integration" "datadog" {
count = var.datadog_integration ? 1 : 0
name = data.pagerduty_vendor.datadog[0].name
service = pagerduty_service.this.id
vendor = data.pagerduty_vendor.datadog[0].id
}