forked from GoogleCloudPlatform/cloud-foundation-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtenant.tf
More file actions
124 lines (117 loc) · 4.11 KB
/
tenant.tf
File metadata and controls
124 lines (117 loc) · 4.11 KB
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
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
# tfdoc:file:description Per-tenant resources.
module "tenant-folder" {
source = "../../../modules/folder"
for_each = local.tenants
parent = module.tenant-core-folder[each.key].id
name = each.value.descriptive_name
contacts = (
each.value.fast_config != null
? {}
: {
(split(":", each.value.admin_principal)[1]) = ["ALL"]
}
)
}
module "tenant-folder-iam" {
source = "../../../modules/folder"
for_each = local.tenants
id = module.tenant-folder[each.key].id
folder_create = false
iam = {
"roles/logging.admin" = compact([
each.value.admin_principal,
module.tenant-sa[each.key].iam_email,
try(module.tenant-automation-tf-resman-sa[each.key].iam_email, null)
])
"roles/owner" = [
each.value.admin_principal,
module.tenant-sa[each.key].iam_email
]
"roles/resourcemanager.folderAdmin" = compact([
each.value.admin_principal,
module.tenant-sa[each.key].iam_email,
try(module.tenant-automation-tf-resman-sa[each.key].iam_email, null)
])
"roles/resourcemanager.projectCreator" = compact([
each.value.admin_principal,
module.tenant-sa[each.key].iam_email,
try(module.tenant-automation-tf-resman-sa[each.key].iam_email, null)
])
"roles/serviceusage.serviceUsageViewer" = compact([
try(module.tenant-automation-tf-resman-r-sa[each.key].iam_email, null)
])
"roles/resourcemanager.tagAdmin" = compact([
try(module.tenant-automation-tf-resman-sa[each.key].iam_email, null)
])
"roles/resourcemanager.tagUser" = compact([
try(module.tenant-automation-tf-resman-sa[each.key].iam_email, null)
])
"roles/viewer" = compact([
try(module.tenant-automation-tf-resman-r-sa[each.key].iam_email, null)
])
}
iam_bindings = each.value.fast_config == null ? {} : {
tenant_iam_admin_conditional = {
members = [module.tenant-automation-tf-resman-sa[each.key].iam_email]
role = "roles/resourcemanager.folderIamAdmin"
condition = {
expression = format(
"api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly([%s])",
join(",", formatlist("'%s'", [
"roles/accesscontextmanager.policyAdmin",
"roles/cloudasset.viewer",
"roles/compute.orgFirewallPolicyAdmin",
"roles/compute.xpnAdmin",
var.custom_roles["tenant_network_admin"]
]))
)
title = "tenant_automation_sa_delegated_grants"
description = "Automation service account delegated grants."
}
}
}
depends_on = [module.tenant-automation-project]
}
# automation service account
module "tenant-sa" {
source = "../../../modules/iam-service-account"
for_each = local.tenants
project_id = var.automation.project_id
name = "${var.names.resource_short_name}-${each.key}-0"
display_name = "Terraform tenant ${each.key} service account."
prefix = var.prefix
iam = {
"roles/iam.serviceAccountTokenCreator" = [each.value.admin_principal]
}
iam_project_roles = {
(var.automation.project_id) = ["roles/serviceusage.serviceUsageConsumer"]
}
}
# automation bucket
module "tenant-gcs" {
source = "../../../modules/gcs"
for_each = local.tenants
project_id = var.automation.project_id
name = "${var.names.resource_short_name}-${each.key}-0"
prefix = var.prefix
location = each.value.locations.gcs
versioning = true
iam = {
"roles/storage.objectAdmin" = [module.tenant-sa[each.key].iam_email]
}
}