-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locals.tf
85 lines (64 loc) · 2.8 KB
/
locals.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
# Local Values
# https://www.terraform.io/language/values/locals
locals {
# Flatten Function
# https://developer.hashicorp.com/terraform/language/functions/flatten
# flatten ensures that this local value is a flat list of objects, rather
# than a list of lists of objects.
environments = { for environment in flatten([
# This will iterate over the folder_services map and return a list of maps based of the values of the environments
# that includes the service key.
for folder_service_key, service in var.folder_services : [
for environment in service.environments : {
service = folder_service_key
environment = environment
}
]
]) : "${environment.service}-${lower(environment.environment)}" => environment }
managers = { for manager in flatten([
# This will iterate over the identity_groups map and return a list of maps based of the values of the managers
# that includes the group key.
for identity_group_key, group in var.identity_groups : [
for manager in group.managers : {
group = identity_group_key
manager = manager
}
]
]) : "${manager.group}-${manager.manager}" => manager }
members = { for member in flatten([
# This will iterate over the identity_groups map and return a list of maps based of the values of the members
# that includes the group key.
for identity_group_key, group in var.identity_groups : [
for member in group.members : {
group = identity_group_key
member = member
}
]
]) : "${member.group}-${member.member}" => member }
owners = { for owner in flatten([
# This will iterate over the identity_groups map and return a list of maps based of the values of the owners
# that includes the group key.
for identity_group_key, group in var.identity_groups : [
for owner in group.owners : {
group = identity_group_key
owner = owner
# Split Function
# https://developer.hashicorp.com/terraform/language/functions/split
# This will split the owner string into a list of strings based on the @ symbol.
# We do this because the owner string is an email address and we want to use the
# the group plus the first part of the email address as resource name key.
owner_split = split("@", owner)
}
]
]) : "${owner.group}-${owner.owner_split[0]}" => owner }
roles = { for role in flatten([
# This will iterate over the identity_groups map and return a list of maps based of the values of the roles
# that includes the group key.
for identity_group_key, group in var.identity_groups : [
for role in group.roles : {
group = identity_group_key
role = role
}
]
]) : "${role.group}-${lower(replace(role.role, "/([/.])/", "-"))}" => role }
}