-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorg_policy.tf
157 lines (133 loc) · 5.09 KB
/
org_policy.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
/**
* Copyright 2021 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.
*/
locals {
organization_id = local.parent_folder != "" ? null : local.org_id
folder_id = local.parent_folder != "" ? local.parent_folder : null
policy_for = local.parent_folder != "" ? "folder" : "organization"
essential_contacts_domains_to_allow = concat(
[for domain in var.essential_contacts_domains_to_allow : domain if can(regex("^@.*$", domain)) == true],
[for domain in var.essential_contacts_domains_to_allow : "@${domain}" if can(regex("^@.*$", domain)) == false]
)
boolean_type_organization_policies = toset([
"compute.disableNestedVirtualization",
"compute.disableSerialPortAccess",
"compute.skipDefaultNetworkCreation",
"compute.restrictXpnProjectLienRemoval",
"compute.disableVpcExternalIpv6",
"compute.setNewProjectDefaultToZonalDNSOnly",
"compute.requireOsLogin",
"sql.restrictPublicIp",
"sql.restrictAuthorizedNetworks",
"iam.disableServiceAccountKeyCreation",
"iam.automaticIamGrantsForDefaultServiceAccounts",
"iam.disableServiceAccountKeyUpload",
"storage.uniformBucketLevelAccess",
"storage.publicAccessPrevention"
])
private_pools = [local.cloud_build_private_worker_pool_id]
}
module "organization_policies_type_boolean" {
source = "terraform-google-modules/org-policy/google"
version = "~> 5.1"
for_each = local.boolean_type_organization_policies
organization_id = local.organization_id
folder_id = local.folder_id
policy_for = local.policy_for
policy_type = "boolean"
enforce = "true"
constraint = "constraints/${each.value}"
}
/******************************************
Compute org policies
*******************************************/
module "org_vm_external_ip_access" {
source = "terraform-google-modules/org-policy/google"
version = "~> 5.1"
organization_id = local.organization_id
folder_id = local.folder_id
policy_for = local.policy_for
policy_type = "list"
enforce = "true"
constraint = "constraints/compute.vmExternalIpAccess"
}
module "restrict_protocol_fowarding" {
source = "terraform-google-modules/org-policy/google"
version = "~> 5.1"
organization_id = local.organization_id
folder_id = local.folder_id
policy_for = local.policy_for
policy_type = "list"
allow = ["INTERNAL"]
allow_list_length = 1
constraint = "constraints/compute.restrictProtocolForwardingCreationForTypes"
}
/******************************************
IAM
*******************************************/
resource "time_sleep" "wait_logs_export" {
create_duration = "30s"
depends_on = [
module.logs_export
]
}
module "org_domain_restricted_sharing" {
source = "terraform-google-modules/org-policy/google//modules/domain_restricted_sharing"
version = "~> 5.1"
organization_id = local.organization_id
folder_id = local.folder_id
policy_for = local.policy_for
domains_to_allow = var.domains_to_allow
depends_on = [
time_sleep.wait_logs_export
]
}
/******************************************
Essential Contacts
*******************************************/
module "domain_restricted_contacts" {
source = "terraform-google-modules/org-policy/google"
version = "~> 5.1"
organization_id = local.organization_id
folder_id = local.folder_id
policy_for = local.policy_for
policy_type = "list"
allow_list_length = length(local.essential_contacts_domains_to_allow)
allow = local.essential_contacts_domains_to_allow
constraint = "constraints/essentialcontacts.allowedContactDomains"
}
/******************************************
Cloud build
*******************************************/
module "allowed_worker_pools" {
source = "terraform-google-modules/org-policy/google"
version = "~> 5.1"
count = var.enforce_allowed_worker_pools && local.cloud_build_private_worker_pool_id != "" ? 1 : 0
organization_id = local.organization_id
folder_id = local.folder_id
policy_for = local.policy_for
policy_type = "list"
allow_list_length = length(local.private_pools)
allow = local.private_pools
constraint = "constraints/cloudbuild.allowedWorkerPools"
}
/******************************************
Access Context Manager Policy
*******************************************/
resource "google_access_context_manager_access_policy" "access_policy" {
count = var.create_access_context_manager_access_policy ? 1 : 0
parent = "organizations/${local.org_id}"
title = "default policy"
}