-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteams.tf
56 lines (50 loc) · 1.48 KB
/
teams.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
# Teams
resource "pagerduty_team" "teams" {
for_each = local.teams
name = each.value.name
description = each.value.description
}
resource "pagerduty_user" "users" {
for_each = local.users
name = each.value.name
email = each.value.email
role = each.value.role
job_title = each.value.job_title
}
resource "pagerduty_user_contact_method" "phone" {
for_each = local.users
user_id = pagerduty_user.users[each.key].id
type = "phone_contact_method"
country_code = each.value.country_code
address = each.value.phone
label = "Mobile"
}
resource "pagerduty_user_contact_method" "sms" {
for_each = local.users
user_id = pagerduty_user.users[each.key].id
type = "sms_contact_method"
country_code = each.value.country_code
address = each.value.sms
label = "Mobile"
}
locals {
# flatten ensures that this local value is a flat list of objects, rather
# than a list of lists of objects.
team_memberships = flatten([
for team_key, team in local.teams : [
for user_key, role in team.members : {
team = team_key
user = user_key
role = role
}
]
])
}
resource "pagerduty_team_membership" "teams" {
for_each = {
for membership in local.team_memberships : "${membership.team}/${membership.user}" => membership
}
team_id = pagerduty_team.teams[each.value.team].id
user_id = pagerduty_user.users[each.value.user].id
role = each.value.role
}