-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.tf
150 lines (125 loc) · 4.49 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
locals {
depends_on_users = [for object in module.users : object.user.name]
}
module "policy_documents" {
source = "./modules/policy_document"
for_each = { for document in var.policy_documents : document.name => document }
template = try(each.value.template, null)
templates = try(each.value.templates, [])
template_paths = each.value.template_paths
template_vars = each.value.template_vars
}
module "policies" {
source = "./modules/policy"
for_each = { for policy in var.policies : policy.name => policy }
name = each.key
# First, try to get the policy from the policy documents module
# Second, just use the policy attribute directly
policy = try(
module.policy_documents[each.value.policy].policy_document,
each.value.policy,
)
description = each.value.description
path = each.value.path
tags = each.value.tags
}
module "groups" {
source = "./modules/group"
for_each = { for group in var.groups : group.name => group }
name = each.key
path = each.value.path
user_names = each.value.user_names
inline_policies = [for policy in each.value.inline_policies : {
name = policy.name
# First, try to get the inline policy from the policy documents module
# Second, just use the policy attribute directly
policy = try(
module.policy_documents[policy.policy].policy_document,
policy.policy
)
}]
managed_policies = [for policy in each.value.managed_policies : {
name = policy.name
# First, try to get the managed policy arn from the policies module
# Second, just use the arn attribute directly
arn = try(
module.policies[policy.name].policy.arn,
policy.arn
)
}]
depends_on_users = local.depends_on_users
}
module "roles" {
source = "./modules/role"
for_each = { for role in var.roles : role.name => role }
name = each.key
# First, try to get the assume role policy from the policy documents module
# Second, just use the assume role policy attribute directly
assume_role_policy = try(
module.policy_documents[each.value.assume_role_policy].policy_document,
each.value.assume_role_policy
)
description = each.value.description
force_detach_policies = each.value.force_detach_policies
instance_profile = each.value.instance_profile
max_session_duration = each.value.max_session_duration
path = each.value.path
tags = each.value.tags
inline_policies = [for policy in each.value.inline_policies : {
name = policy.name
# First, try to get the inline policy from the policy documents module
# Second, just use the policy attribute directly
policy = try(
module.policy_documents[policy.policy].policy_document,
policy.policy
)
}]
managed_policies = [for policy in each.value.managed_policies : {
name = policy.name
# First, try to get the managed policy arn from the policies module
# Second, just use the arn attribute directly
arn = try(
module.policies[policy.name].policy.arn,
policy.arn
)
}]
# First, try to get the permissions boundary arn from the policies module
# Second, just use the permissions boundary attribute directly
permissions_boundary = try(
module.policies[each.value.permissions_boundary].policy.arn,
each.value.permissions_boundary
)
}
module "users" {
source = "./modules/user"
for_each = { for user in var.users : user.name => user }
name = each.key
access_keys = each.value.access_keys
force_destroy = each.value.force_destroy
path = each.value.path
tags = each.value.tags
inline_policies = [for policy in each.value.inline_policies : {
name = policy.name
# First, try to get the inline policy from the policy documents module
# Second, just use the policy attribute directly
policy = try(
module.policy_documents[policy.policy].policy_document,
policy.policy
)
}]
managed_policies = [for policy in each.value.managed_policies : {
name = policy.name
# First, try to get the managed policy arn from the policies module
# Second, just use the arn attribute directly
arn = try(
module.policies[policy.name].policy.arn,
policy.arn
)
}]
# First, try to get the permissions boundary arn from the policies module
# Second, just use the permissions boundary attribute directly
permissions_boundary = try(
module.policies[each.value.permissions_boundary].policy.arn,
each.value.permissions_boundary
)
}