generated from appvia/terraform-aws-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocals.tf
168 lines (163 loc) · 5.1 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
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
locals {
## All member accounts in the organization which are active
all_member_accounts = {
for x in data.aws_organizations_organizational_unit_descendant_accounts.current.accounts :
x.name => {
arn = x.arn
email = x.email
id = x.id
name = x.name
status = x.status
} if x.status == "ACTIVE"
}
## Build a map of the service quotas
service_quotas = {
for quota in var.service_quotas : "${quota.service_code}-${quota.quota_code}" => {
service_code = quota.service_code
quota_code = quota.quota_code
value = quota.value
}
}
## Build of a map of all the organizational units from the data lookup
current_units = {
for ou in data.aws_organizations_organizational_units.current.children : lower(ou.name) => ou.id
}
## The root organizational unit
root_ou = aws_organizations_organization.organization.roots[0].id
## Build all the level 1 organizational units
level_1_ou_arguments = [
for ou in var.organization.units :
{
name : ou.name,
key : ou.key,
}
]
## Build all the level 2 organizational units
level_2_ou_arguments = flatten([
for level_1_ou in var.organization.units :
[
for level_2_ou in level_1_ou.units :
{
name : level_2_ou.name,
key : level_2_ou.key,
parent : level_1_ou.key
}
]
])
## Build all the level 3 organizational units
level_3_ou_arguments = flatten([
for level_1_ou in var.organization.units :
[
for level_2_ou in level_1_ou.units :
[
for level_3_ou in level_2_ou.units :
{
name : level_3_ou.name,
key : level_3_ou.key,
parent : level_2_ou.key
}
]
]
])
## Build all the level 4 organizational units
level_4_ou_arguments = flatten([
for level_1_ou in var.organization.units :
[
for level_2_ou in level_1_ou.units :
[
for level_3_ou in level_2_ou.units :
[
for level_4_ou in level_3_ou.units :
{
name : level_4_ou.name,
key : level_4_ou.key,
parent : level_3_ou.key
}
]
]
]
])
## Build all the level 5 organizational units
level_5_ou_arguments = flatten([
for level_1_ou in var.organization.units :
[
for level_2_ou in level_1_ou.units :
[
for level_3_ou in level_2_ou.units :
[
for level_4_ou in level_3_ou.units :
[
for level_5_ou in level_4_ou.units :
{
name : level_5_ou.name,
key : level_5_ou.key,
parent : level_4_ou.key
}
]
]
]
]
])
}
locals {
level_1_ou_attributes = [
for ou in local.level_1_ou_arguments :
{
key = ou.key
id = aws_organizations_organizational_unit.level_1_ous[ou.key].id,
arn = aws_organizations_organizational_unit.level_1_ous[ou.key].arn,
parent_id = aws_organizations_organizational_unit.level_1_ous[ou.key].parent_id,
name = aws_organizations_organizational_unit.level_1_ous[ou.key].name,
}
]
level_2_ou_attributes = [
for ou in local.level_2_ou_arguments :
{
key = ou.key
id = aws_organizations_organizational_unit.level_2_ous[ou.key].id,
arn = aws_organizations_organizational_unit.level_2_ous[ou.key].arn,
parent_id = aws_organizations_organizational_unit.level_2_ous[ou.key].parent_id,
name = aws_organizations_organizational_unit.level_2_ous[ou.key].name,
}
]
level_3_ou_attributes = [
for ou in local.level_3_ou_arguments :
{
key = ou.key
id = aws_organizations_organizational_unit.level_3_ous[ou.key].id,
arn = aws_organizations_organizational_unit.level_3_ous[ou.key].arn,
parent_id = aws_organizations_organizational_unit.level_3_ous[ou.key].parent_id,
name = aws_organizations_organizational_unit.level_3_ous[ou.key].name,
}
]
level_4_ou_attributes = [
for ou in local.level_4_ou_arguments :
{
key = ou.key
id = aws_organizations_organizational_unit.level_4_ous[ou.key].id,
arn = aws_organizations_organizational_unit.level_4_ous[ou.key].arn,
parent_id = aws_organizations_organizational_unit.level_4_ous[ou.key].parent_id,
name = aws_organizations_organizational_unit.level_4_ous[ou.key].name,
}
]
level_5_ou_attributes = [
for ou in local.level_5_ou_arguments :
{
key = ou.key
id = aws_organizations_organizational_unit.level_5_ous[ou.key].id,
arn = aws_organizations_organizational_unit.level_5_ous[ou.key].arn,
parent_id = aws_organizations_organizational_unit.level_5_ous[ou.key].parent_id,
name = aws_organizations_organizational_unit.level_5_ous[ou.key].name,
}
]
all_ou_attributes = {
for ou in concat(
local.level_1_ou_attributes,
local.level_2_ou_attributes,
local.level_3_ou_attributes,
local.level_4_ou_attributes,
local.level_5_ou_attributes
) :
ou.key => ou
}
}