-
Notifications
You must be signed in to change notification settings - Fork 2
/
org.tf
58 lines (47 loc) · 1.6 KB
/
org.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
resource "aws_organizations_organization" "root" {
aws_service_access_principals = toset(
local.enable_sso ? concat(
local.organization_config["service_access_principals"],
["sso.amazonaws.com"],
) : local.organization_config["service_access_principals"]
)
feature_set = local.organization_config["feature_set"]
enabled_policy_types = local.organization_config["enabled_policy_types"]
lifecycle {
prevent_destroy = true
}
}
resource "aws_organizations_organizational_unit" "unit" {
for_each = local.organization_config["units"]
name = each.key
parent_id = aws_organizations_organization.root.roots[0].id
tags = {
"Name" = each.key
}
lifecycle {
prevent_destroy = true
}
}
resource "aws_organizations_account" "account" {
for_each = {
for account in flatten([
for unit_name, unit in local.organization_config["units"] : [
for account_name in keys(local.organization_config["units"][unit_name]["accounts"]) : merge(
local.organization_config["units"][unit_name]["accounts"][account_name],
{ "org_unit_name" = unit_name },
{ "account_name" = account_name },
)
]
]) : account["account_name"] => account
}
name = each.key
email = each.value["email"]
iam_user_access_to_billing = lookup(each.value, "iam_user_access_to_billing", "ALLOW") == "NULL" ? null : lookup(each.value, "iam_user_access_to_billing", "ALLOW")
parent_id = aws_organizations_organizational_unit.unit[each.value["org_unit_name"]].id
tags = {
"Name" = each.key
}
lifecycle {
prevent_destroy = true
}
}