2022-01-19 05:17:20 -08:00
|
|
|
/**
|
2024-02-12 05:35:30 -08:00
|
|
|
* Copyright 2024 Google LLC
|
2022-01-19 05:17:20 -08:00
|
|
|
*
|
|
|
|
* 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 Security stage resources.
|
|
|
|
|
2024-04-04 01:26:35 -07:00
|
|
|
locals {
|
|
|
|
# FAST-specific IAM
|
|
|
|
_security_folder_fast_iam = {
|
|
|
|
"roles/logging.admin" = [module.branch-security-sa.iam_email]
|
|
|
|
"roles/owner" = [module.branch-security-sa.iam_email]
|
|
|
|
"roles/resourcemanager.folderAdmin" = [module.branch-security-sa.iam_email]
|
|
|
|
"roles/resourcemanager.projectCreator" = [module.branch-security-sa.iam_email]
|
|
|
|
# read-only (plan) automation service account
|
|
|
|
"roles/viewer" = [module.branch-security-r-sa.iam_email]
|
|
|
|
"roles/resourcemanager.folderViewer" = [module.branch-security-r-sa.iam_email]
|
|
|
|
}
|
|
|
|
|
|
|
|
# deep-merge FAST-specific IAM with user-provided bindings in var.folder_iam
|
|
|
|
_security_folder_iam = merge(
|
|
|
|
var.folder_iam.security,
|
|
|
|
{
|
|
|
|
for role, principals in local._security_folder_fast_iam :
|
|
|
|
role => distinct(concat(principals, lookup(var.folder_iam.security, role, [])))
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-19 05:17:20 -08:00
|
|
|
module "branch-security-folder" {
|
|
|
|
source = "../../../modules/folder"
|
2024-05-15 02:17:13 -07:00
|
|
|
parent = local.root_node
|
2022-01-19 05:17:20 -08:00
|
|
|
name = "Security"
|
2024-02-12 05:35:30 -08:00
|
|
|
iam_by_principals = {
|
|
|
|
(local.principals.gcp-security-admins) = [
|
2023-12-27 03:33:16 -08:00
|
|
|
# owner and viewer roles are broad and might grant unwanted access
|
|
|
|
# replace them with more selective custom roles for production deployments
|
|
|
|
"roles/editor"
|
2022-01-19 05:17:20 -08:00
|
|
|
]
|
|
|
|
}
|
2024-04-04 01:26:35 -07:00
|
|
|
iam = local._security_folder_iam
|
2022-02-20 02:26:30 -08:00
|
|
|
tag_bindings = {
|
2022-04-13 01:22:33 -07:00
|
|
|
context = try(
|
2024-05-15 02:17:13 -07:00
|
|
|
local.tag_values["${var.tag_names.context}/security"].id, null
|
2022-04-13 01:22:33 -07:00
|
|
|
)
|
2022-02-20 02:26:30 -08:00
|
|
|
}
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
|
2023-12-27 03:33:16 -08:00
|
|
|
# automation service account
|
2022-04-11 23:17:27 -07:00
|
|
|
|
2022-01-19 05:17:20 -08:00
|
|
|
module "branch-security-sa" {
|
2024-05-15 02:17:13 -07:00
|
|
|
source = "../../../modules/iam-service-account"
|
|
|
|
project_id = var.automation.project_id
|
|
|
|
name = "prod-resman-sec-0"
|
|
|
|
display_name = "Terraform resman security service account."
|
|
|
|
prefix = var.prefix
|
|
|
|
service_account_create = var.root_node == null
|
2022-04-11 23:17:27 -07:00
|
|
|
iam = {
|
|
|
|
"roles/iam.serviceAccountTokenCreator" = compact([
|
2024-04-17 01:23:48 -07:00
|
|
|
try(module.branch-security-sa-cicd[0].iam_email, null)
|
2022-04-11 23:17:27 -07:00
|
|
|
])
|
|
|
|
}
|
2023-05-15 03:20:33 -07:00
|
|
|
iam_project_roles = {
|
2023-10-18 05:18:31 -07:00
|
|
|
(var.automation.project_id) = ["roles/serviceusage.serviceUsageConsumer"]
|
2023-05-15 03:20:33 -07:00
|
|
|
}
|
2022-04-11 23:17:27 -07:00
|
|
|
iam_storage_roles = {
|
2023-03-17 09:24:55 -07:00
|
|
|
(var.automation.outputs_bucket) = ["roles/storage.objectAdmin"]
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
|
2023-12-27 03:33:16 -08:00
|
|
|
# automation read-only service account
|
|
|
|
|
|
|
|
module "branch-security-r-sa" {
|
2024-05-15 02:17:13 -07:00
|
|
|
source = "../../../modules/iam-service-account"
|
|
|
|
project_id = var.automation.project_id
|
|
|
|
name = "prod-resman-sec-0r"
|
|
|
|
display_name = "Terraform resman security service account (read-only)."
|
|
|
|
prefix = var.prefix
|
|
|
|
service_account_create = var.root_node == null
|
2023-12-27 03:33:16 -08:00
|
|
|
iam = {
|
|
|
|
"roles/iam.serviceAccountTokenCreator" = compact([
|
2024-04-17 01:23:48 -07:00
|
|
|
try(module.branch-security-r-sa-cicd[0].iam_email, null)
|
2023-12-27 03:33:16 -08:00
|
|
|
])
|
|
|
|
}
|
|
|
|
iam_project_roles = {
|
|
|
|
(var.automation.project_id) = ["roles/serviceusage.serviceUsageConsumer"]
|
|
|
|
}
|
|
|
|
iam_storage_roles = {
|
|
|
|
(var.automation.outputs_bucket) = [var.custom_roles["storage_viewer"]]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# automation bucket
|
|
|
|
|
2022-01-19 05:17:20 -08:00
|
|
|
module "branch-security-gcs" {
|
2022-09-08 06:24:42 -07:00
|
|
|
source = "../../../modules/gcs"
|
|
|
|
project_id = var.automation.project_id
|
|
|
|
name = "prod-resman-sec-0"
|
|
|
|
prefix = var.prefix
|
|
|
|
location = var.locations.gcs
|
|
|
|
storage_class = local.gcs_storage_class
|
|
|
|
versioning = true
|
2022-01-19 05:17:20 -08:00
|
|
|
iam = {
|
2023-12-27 03:33:16 -08:00
|
|
|
"roles/storage.objectAdmin" = [module.branch-security-sa.iam_email]
|
|
|
|
"roles/storage.objectViewer" = [module.branch-security-r-sa.iam_email]
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
}
|