-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.tf
173 lines (149 loc) · 7.17 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* Copyright 2023 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 {
pubsub_resource_location = lower(var.pubsub_resource_location)
location = lower(var.location)
cmek_location = local.location == "eu" ? "europe" : local.location
projects_to_remove_owner = var.remove_owner_role ? local.projects_ids : {}
projects_ids = {
data_ingestion = var.data_ingestion_project_id
governance = var.data_governance_project_id
data = var.data_project_id
}
restricted_non_cmek_services = {
data_ingestion = []
governance = []
data = ["bigquery.googleapis.com"]
}
}
resource "google_project_iam_binding" "remove_owner_role" {
for_each = local.projects_to_remove_owner
project = each.value
role = "roles/owner"
members = []
}
/**
* Data Governance project
*/
module "data_governance_sa" {
source = "./modules/data-governance-sa"
data_project_id = var.data_project_id
terraform_service_account = var.terraform_service_account
data_ingestion_project_id = var.data_ingestion_project_id
data_governance_project_id = var.data_governance_project_id
}
module "data_governance" {
source = "./modules/data-governance"
labels = var.labels
data_ingestion_project_number = var.data_ingestion_project_number
data_governance_project_id = var.data_governance_project_id
data_project_number = var.data_project_number
cmek_location = local.cmek_location
cmek_keyring_name = var.cmek_keyring_name
key_rotation_period_seconds = var.key_rotation_period_seconds
delete_contents_on_destroy = var.delete_contents_on_destroy
kms_key_protection_level = var.kms_key_protection_level
data_ingestion_gcs_sa_account = module.data_governance_sa.data_ingestion_gcs_sa_account
data_ingestion_artifact_registry_sa_account = module.data_governance_sa.data_ingestion_artifact_registry_sa_account
data_ingestion_eventarc_sa_account = module.data_governance_sa.data_ingestion_eventarc_sa_account
data_ingestion_pubsub_sa_account = module.data_governance_sa.data_ingestion_pubsub_sa_account
data_ingestion_dataflow_sa_account = module.data_governance_sa.data_ingestion_dataflow_sa_account
data_governance_bigquery_sa_account = module.data_governance_sa.data_governance_bigquery_sa_account
data_bq_encryption_service_sa_account = module.data_governance_sa.data_bq_encryption_service_sa_account
data_gcs_sa_account = module.data_governance_sa.data_gcs_sa_account
data_bigquery_sa_account = module.data_governance_sa.data_bigquery_sa_account
data_dataflow_sa_account = module.data_governance_sa.data_dataflow_sa_account
bq_location = local.location
dlp_output_dataset = var.dlp_output_dataset
dataset_default_table_expiration_ms = var.dataset_default_table_expiration_ms
depends_on = [
time_sleep.wait_for_bridge_propagation
]
}
/**
* Data Ingestion project
*/
module "data_ingestion_sa" {
source = "./modules/data-ingestion-sa"
data_ingestion_project_id = var.data_ingestion_project_id
data_governance_project_id = var.data_governance_project_id
enable_bigquery_read_roles = var.enable_bigquery_read_roles_in_data_ingestion
service_account_users = {
terraform_sa = "serviceAccount:${var.terraform_service_account}"
data_engineer = "group:${var.data_engineer_group}"
data_analyst = "group:${var.data_analyst_group}"
}
}
module "data_ingestion" {
source = "./modules/data-ingestion"
labels = var.labels
bucket_name = var.bucket_name
bucket_class = var.bucket_class
bucket_lifecycle_rules = var.bucket_lifecycle_rules
delete_contents_on_destroy = var.delete_contents_on_destroy
data_ingestion_project_id = var.data_ingestion_project_id
data_ingestion_project_number = var.data_ingestion_project_number
pubsub_resource_location = local.pubsub_resource_location
bucket_location = local.location
data_ingestion_encryption_key = module.data_governance.cmek_data_ingestion_crypto_key
dataflow_controller_service_account_email = module.data_ingestion_sa.dataflow_controller_service_account_email
storage_writer_service_account_email = module.data_ingestion_sa.storage_writer_service_account_email
pubsub_writer_service_account_email = module.data_ingestion_sa.pubsub_writer_service_account_email
cloudfunction_controller_service_account_email = module.data_ingestion_sa.cloudfunction_controller_service_account_email
depends_on = [
time_sleep.wait_for_bridge_propagation
]
}
/**
* Data project
*/
module "bigquery_data" {
source = "./modules/data"
project_id = var.data_project_id
dataset_id = var.dataset_id
dataset_name = var.dataset_name
dataset_description = var.dataset_description
labels = var.labels
location = local.location
bigquery_encryption_key = module.data_governance.cmek_data_bigquery_crypto_key
dataflow_controller_service_account_email = module.data_ingestion_sa.dataflow_controller_service_account_email
terraform_service_account = var.terraform_service_account
delete_contents_on_destroy = var.delete_contents_on_destroy
dataset_default_table_expiration_ms = var.dataset_default_table_expiration_ms
access = [{
role = "roles/bigquery.dataOwner"
user_by_email = module.data_ingestion_sa.cloudfunction_controller_service_account_email
}]
depends_on = [
time_sleep.wait_for_bridge_propagation
]
}
/**
* Organization projects setup
*/
module "org_policies" {
source = "./modules/organization-policies"
for_each = local.projects_ids
project_id = each.value
trusted_locations = var.trusted_locations
trusted_shared_vpc_subnetworks = var.trusted_shared_vpc_subnetworks
domains_to_allow = var.domains_to_allow
restricted_non_cmek_services = local.restricted_non_cmek_services[each.key]
depends_on = [
module.data_ingestion,
module.bigquery_data
]
}