cloud-foundation-fabric/examples/data-solutions/gcs-to-bq-with-least-privil.../main.tf

107 lines
3.4 KiB
Terraform
Raw Normal View History

2022-01-13 23:38:26 -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-01-14 09:29:10 -08:00
locals {
2022-01-14 07:59:10 -08:00
iam = {
# GCS roles
"roles/storage.objectAdmin" = [
module.service-account-df.iam_email,
module.service-account-landing.iam_email
],
"roles/storage.objectViewer" = [
module.service-account-orch.iam_email,
],
2022-01-14 08:55:12 -08:00
# BigQuery roles
2022-01-14 07:59:10 -08:00
"roles/bigquery.admin" = concat([
module.service-account-orch.iam_email,
2022-01-14 07:59:10 -08:00
], var.data_eng_principals
)
"roles/bigquery.dataEditor" = [
module.service-account-df.iam_email,
2022-01-14 04:55:47 -08:00
module.service-account-bq.iam_email
]
"roles/bigquery.dataViewer" = [
module.service-account-bq.iam_email,
module.service-account-orch.iam_email
]
"roles/bigquery.jobUser" = [
2022-01-14 04:55:47 -08:00
module.service-account-df.iam_email,
module.service-account-bq.iam_email
]
"roles/bigquery.user" = [
module.service-account-bq.iam_email,
module.service-account-df.iam_email
]
2022-01-14 08:55:12 -08:00
# common roles
"roles/logging.logWriter" = [
module.service-account-bq.iam_email,
module.service-account-landing.iam_email,
module.service-account-orch.iam_email,
]
"roles/monitoring.metricWriter" = [
module.service-account-bq.iam_email,
module.service-account-landing.iam_email,
module.service-account-orch.iam_email,
]
"roles/iam.serviceAccountUser" = [
module.service-account-orch.iam_email,
]
2022-01-14 00:32:15 -08:00
"roles/iam.serviceAccountTokenCreator" = concat(
2022-01-14 04:55:47 -08:00
var.data_eng_principals
2022-01-14 00:32:15 -08:00
)
2022-01-14 08:55:12 -08:00
# Dataflow roles
"roles/dataflow.admin" = concat(
[module.service-account-orch.iam_email],
var.data_eng_principals
2022-01-14 04:55:47 -08:00
)
2022-01-14 01:28:19 -08:00
"roles/dataflow.worker" = [
module.service-account-df.iam_email,
]
"roles/dataflow.developer" = var.data_eng_principals
"roles/compute.viewer" = var.data_eng_principals
2022-01-14 08:55:12 -08:00
# network roles
2022-01-14 01:28:19 -08:00
"roles/compute.networkUser" = [
module.service-account-df.iam_email,
2022-01-14 04:55:47 -08:00
"serviceAccount:${module.project.service_accounts.robots.dataflow}"
2022-01-14 01:28:19 -08:00
]
2022-01-13 23:50:58 -08:00
}
2022-01-14 09:29:10 -08:00
}
module "project" {
source = "../../../modules/project"
name = var.project_id
parent = try(var.project_create.parent, null)
billing_account = try(var.project_create.billing_account_id, null)
project_create = var.project_create != null
prefix = var.project_create == null ? null : var.prefix
services = [
"bigquery.googleapis.com",
"bigquerystorage.googleapis.com",
"bigqueryreservation.googleapis.com",
"cloudkms.googleapis.com",
"compute.googleapis.com",
"dataflow.googleapis.com",
"servicenetworking.googleapis.com",
"storage.googleapis.com",
"storage-component.googleapis.com",
]
2022-01-14 09:29:10 -08:00
# additive IAM bindings avoid disrupting bindings in existing project
iam = var.project_create != null ? local.iam : {}
iam_additive = var.project_create == null ? local.iam : {}
2022-01-14 04:55:47 -08:00
service_config = {
disable_on_destroy = false, disable_dependent_services = false
}
}