2022-01-17 23:58:14 -08:00
# Copyright 2022 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
#
# https://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.
2022-04-21 14:53:16 -07:00
# tfdoc:file:description Data Warehouse projects.
2022-01-31 21:41:33 -08:00
2022-01-17 23:58:14 -08:00
locals {
2022-04-21 14:53:16 -07:00
dwh_lnd_iam = {
2022-04-01 09:25:05 -07:00
" roles/bigquery.dataOwner " = [
2022-02-09 08:01:25 -08:00
module . load - sa - df -0 . iam_email ,
2023-02-21 16:36:01 -08:00
]
" roles/bigquery.dataViewer " = [
2022-02-12 07:06:06 -08:00
module . transf - sa - df -0 . iam_email ,
module . transf - sa - bq -0 . iam_email ,
2023-02-21 16:36:01 -08:00
local . groups_iam . data - engineers
2022-01-17 23:58:14 -08:00
]
" roles/bigquery.jobUser " = [
2023-02-21 16:36:01 -08:00
module . load - sa - df -0 . iam_email , local . groups_iam . data - engineers
2022-02-12 00:48:16 -08:00
]
2023-02-21 16:36:01 -08:00
" roles/datacatalog.categoryAdmin " = [ module . transf - sa - bq -0 . iam_email ]
" roles/datacatalog.tagTemplateViewer " = [ local . groups_iam . data - engineers ]
" roles/datacatalog.viewer " = [ local . groups_iam . data - engineers ]
" roles/storage.objectCreator " = [ module . load - sa - df -0 . iam_email ]
" roles/storage.objectViewer " = [ local . groups_iam . data - engineers ]
2022-02-12 00:48:16 -08:00
}
2022-04-21 14:53:16 -07:00
dwh_iam = {
2022-04-01 09:25:05 -07:00
" roles/bigquery.dataOwner " = [
2022-02-09 08:01:25 -08:00
module . transf - sa - df -0 . iam_email ,
module . transf - sa - bq -0 . iam_email ,
2022-02-12 00:48:16 -08:00
]
2023-02-21 16:36:01 -08:00
" roles/bigquery.dataViewer " = [
local . groups_iam . data - analysts ,
local . groups_iam . data - engineers
]
2022-02-12 00:48:16 -08:00
" roles/bigquery.jobUser " = [
module . transf - sa - bq -0 . iam_email ,
2023-02-21 16:36:01 -08:00
local . groups_iam . data - analysts ,
local . groups_iam . data - engineers
2022-02-12 00:48:16 -08:00
]
2023-02-21 16:36:01 -08:00
" roles/datacatalog.tagTemplateViewer " = [
local . groups_iam . data - analysts , local . groups_iam . data - engineers
2022-04-01 09:25:05 -07:00
]
2023-02-21 16:36:01 -08:00
" roles/datacatalog.viewer " = [
local . groups_iam . data - analysts , local . groups_iam . data - engineers
2022-01-17 23:58:14 -08:00
]
" roles/storage.objectViewer " = [
2023-02-21 16:36:01 -08:00
local . groups_iam . data - analysts , local . groups_iam . data - engineers
2022-01-17 23:58:14 -08:00
]
2023-02-21 16:36:01 -08:00
" roles/storage.objectAdmin " = [ module . transf - sa - df -0 . iam_email ]
2022-01-17 23:58:14 -08:00
}
2022-04-21 14:53:16 -07:00
dwh_services = concat ( var . project_services , [
2022-01-17 23:58:14 -08:00
" bigquery.googleapis.com " ,
" bigqueryreservation.googleapis.com " ,
" bigquerystorage.googleapis.com " ,
" cloudkms.googleapis.com " ,
" compute.googleapis.com " ,
" dataflow.googleapis.com " ,
" pubsub.googleapis.com " ,
" servicenetworking.googleapis.com " ,
" storage.googleapis.com " ,
" storage-component.googleapis.com "
] )
2022-02-09 08:01:25 -08:00
}
# Project
2022-04-21 14:53:16 -07:00
module " dwh-lnd-project " {
2022-02-09 08:01:25 -08:00
source = " ../../../modules/project "
2023-02-19 15:39:37 -08:00
parent = var . project_config . parent
2023-02-19 13:37:32 -08:00
billing_account = var . project_config . billing_account_id
project_create = var . project_config . billing_account_id ! = null
prefix = var . project_config . billing_account_id == null ? null : var . prefix
name = var . project_config . billing_account_id == null ? var . project_config . project_ids . dwh - lnd : " ${ var . project_config . project_ids . dwh - lnd } ${ local . project_suffix } "
2023-02-21 16:36:01 -08:00
iam = var . project_config . billing_account_id ! = null ? local . dwh_lnd_iam : { }
iam_additive = var . project_config . billing_account_id == null ? local . dwh_lnd_iam : { }
services = local . dwh_services
2022-01-19 12:33:24 -08:00
service_encryption_key_ids = {
2022-01-31 08:11:06 -08:00
bq = [ try ( local . service_encryption_keys . bq , null ) ]
storage = [ try ( local . service_encryption_keys . storage , null ) ]
2022-01-19 12:33:24 -08:00
}
2022-01-17 23:58:14 -08:00
}
2022-04-21 14:53:16 -07:00
module " dwh-cur-project " {
2022-01-17 23:58:14 -08:00
source = " ../../../modules/project "
2023-02-19 15:39:37 -08:00
parent = var . project_config . parent
2023-02-19 13:37:32 -08:00
billing_account = var . project_config . billing_account_id
project_create = var . project_config . billing_account_id ! = null
prefix = var . project_config . billing_account_id == null ? null : var . prefix
name = var . project_config . billing_account_id == null ? var . project_config . project_ids . dwh - cur : " ${ var . project_config . project_ids . dwh - cur } ${ local . project_suffix } "
2023-02-21 16:36:01 -08:00
iam = var . project_config . billing_account_id ! = null ? local . dwh_iam : { }
iam_additive = var . project_config . billing_account_id == null ? local . dwh_iam : { }
services = local . dwh_services
2022-01-19 12:33:24 -08:00
service_encryption_key_ids = {
2022-01-31 08:11:06 -08:00
bq = [ try ( local . service_encryption_keys . bq , null ) ]
storage = [ try ( local . service_encryption_keys . storage , null ) ]
2022-01-19 12:33:24 -08:00
}
2022-01-17 23:58:14 -08:00
}
2022-04-21 14:53:16 -07:00
module " dwh-conf-project " {
2022-01-17 23:58:14 -08:00
source = " ../../../modules/project "
2023-02-19 15:39:37 -08:00
parent = var . project_config . parent
2023-02-19 13:37:32 -08:00
billing_account = var . project_config . billing_account_id
project_create = var . project_config . billing_account_id ! = null
prefix = var . project_config . billing_account_id == null ? null : var . prefix
name = var . project_config . billing_account_id == null ? var . project_config . project_ids . dwh - conf : " ${ var . project_config . project_ids . dwh - conf } ${ local . project_suffix } "
2023-02-21 16:36:01 -08:00
iam = var . project_config . billing_account_id ! = null ? local . dwh_iam : null
iam_additive = var . project_config . billing_account_id == null ? local . dwh_iam : null
services = local . dwh_services
2022-01-19 12:33:24 -08:00
service_encryption_key_ids = {
2022-01-31 08:11:06 -08:00
bq = [ try ( local . service_encryption_keys . bq , null ) ]
storage = [ try ( local . service_encryption_keys . storage , null ) ]
2022-01-19 12:33:24 -08:00
}
2022-01-17 23:58:14 -08:00
}
2022-02-09 08:01:25 -08:00
# Bigquery
2022-04-21 14:53:16 -07:00
module " dwh-lnd-bq-0 " {
2022-02-09 08:01:25 -08:00
source = " ../../../modules/bigquery-dataset "
2022-04-21 14:53:16 -07:00
project_id = module . dwh - lnd - project . project_id
id = " ${ replace ( var . prefix , " - " , " _ " ) } _dwh_lnd_bq_0 "
2022-02-11 15:50:38 -08:00
location = var . location
2022-02-09 08:01:25 -08:00
encryption_key = try ( local . service_encryption_keys . bq , null )
}
2022-04-21 14:53:16 -07:00
module " dwh-cur-bq-0 " {
2022-02-09 08:01:25 -08:00
source = " ../../../modules/bigquery-dataset "
2022-04-21 14:53:16 -07:00
project_id = module . dwh - cur - project . project_id
2023-02-19 15:39:37 -08:00
id = " ${ replace ( var . prefix , " - " , " _ " ) } _dwh_cur_bq_0 "
2022-02-11 15:50:38 -08:00
location = var . location
2022-02-09 08:01:25 -08:00
encryption_key = try ( local . service_encryption_keys . bq , null )
}
2022-04-21 14:53:16 -07:00
module " dwh-conf-bq-0 " {
2022-02-09 08:01:25 -08:00
source = " ../../../modules/bigquery-dataset "
2022-04-21 14:53:16 -07:00
project_id = module . dwh - conf - project . project_id
id = " ${ replace ( var . prefix , " - " , " _ " ) } _dwh_conf_bq_0 "
2022-02-11 15:50:38 -08:00
location = var . location
2022-02-09 08:01:25 -08:00
encryption_key = try ( local . service_encryption_keys . bq , null )
}
# Cloud storage
2022-04-21 14:53:16 -07:00
module " dwh-lnd-cs-0 " {
2022-02-09 08:01:25 -08:00
source = " ../../../modules/gcs "
2022-04-21 14:53:16 -07:00
project_id = module . dwh - lnd - project . project_id
2022-02-09 08:01:25 -08:00
prefix = var . prefix
2022-04-21 14:53:16 -07:00
name = " dwh-lnd-cs-0 "
2022-02-11 15:50:38 -08:00
location = var . location
storage_class = " MULTI_REGIONAL "
2022-02-09 08:01:25 -08:00
encryption_key = try ( local . service_encryption_keys . storage , null )
force_destroy = var . data _ force_destroy
}
2022-04-21 14:53:16 -07:00
module " dwh-cur-cs-0 " {
2022-02-09 08:01:25 -08:00
source = " ../../../modules/gcs "
2022-04-21 14:53:16 -07:00
project_id = module . dwh - cur - project . project_id
2022-02-09 08:01:25 -08:00
prefix = var . prefix
2022-04-21 14:53:16 -07:00
name = " dwh-cur-cs-0 "
2022-02-11 15:50:38 -08:00
location = var . location
storage_class = " MULTI_REGIONAL "
2022-02-09 08:01:25 -08:00
encryption_key = try ( local . service_encryption_keys . storage , null )
force_destroy = var . data _ force_destroy
}
2022-04-21 14:53:16 -07:00
module " dwh-conf-cs-0 " {
2022-02-09 08:01:25 -08:00
source = " ../../../modules/gcs "
2022-04-21 14:53:16 -07:00
project_id = module . dwh - conf - project . project_id
2022-02-09 08:01:25 -08:00
prefix = var . prefix
2022-04-21 14:53:16 -07:00
name = " dwh-conf-cs-0 "
2022-02-11 15:50:38 -08:00
location = var . location
storage_class = " MULTI_REGIONAL "
2022-02-09 08:01:25 -08:00
encryption_key = try ( local . service_encryption_keys . storage , null )
force_destroy = var . data _ force_destroy
}