2022-01-19 05:17:20 -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
|
|
|
|
*
|
|
|
|
* 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 {
|
2022-04-11 23:17:27 -07:00
|
|
|
_tpl_providers = "${path.module}/templates/providers.tf.tpl"
|
|
|
|
cicd_workflow_attrs = {
|
|
|
|
data_platform_dev = {
|
|
|
|
service_account = try(module.branch-dp-dev-sa-cicd.0.email, null)
|
|
|
|
tf_providers_file = "03-data-platform-dev-providers.tf"
|
2022-06-08 02:34:08 -07:00
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_3
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
|
|
|
data_platform_prod = {
|
|
|
|
service_account = try(module.branch-dp-prod-sa-cicd.0.email, null)
|
|
|
|
tf_providers_file = "03-data-platform-prod-providers.tf"
|
2022-06-08 02:34:08 -07:00
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_3
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
2022-09-08 23:33:25 -07:00
|
|
|
gke_dev = {
|
|
|
|
service_account = try(module.branch-gke-dev-sa-cicd.0.email, null)
|
|
|
|
tf_providers_file = "03-gke-dev-providers.tf"
|
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_3
|
|
|
|
}
|
|
|
|
gke_prod = {
|
|
|
|
service_account = try(module.branch-gke-prod-sa-cicd.0.email, null)
|
|
|
|
tf_providers_file = "03-gke-prod-providers.tf"
|
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_3
|
|
|
|
}
|
2022-04-11 23:17:27 -07:00
|
|
|
networking = {
|
|
|
|
service_account = try(module.branch-network-sa-cicd.0.email, null)
|
|
|
|
tf_providers_file = "02-networking-providers.tf"
|
2022-06-08 02:34:08 -07:00
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_2
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
|
|
|
project_factory_dev = {
|
2022-06-28 08:33:37 -07:00
|
|
|
service_account = try(module.branch-pf-dev-sa-cicd.0.email, null)
|
2022-04-11 23:17:27 -07:00
|
|
|
tf_providers_file = "03-project-factory-dev-providers.tf"
|
2022-06-08 02:34:08 -07:00
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_3
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
|
|
|
project_factory_prod = {
|
2022-06-28 08:33:37 -07:00
|
|
|
service_account = try(module.branch-pf-prod-sa-cicd.0.email, null)
|
2022-04-11 23:17:27 -07:00
|
|
|
tf_providers_file = "03-project-factory-prod-providers.tf"
|
2022-06-08 02:34:08 -07:00
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_3
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
|
|
|
security = {
|
|
|
|
service_account = try(module.branch-security-sa-cicd.0.email, null)
|
|
|
|
tf_providers_file = "02-security-providers.tf"
|
2022-06-08 02:34:08 -07:00
|
|
|
tf_var_files = local.cicd_workflow_var_files.stage_2
|
2022-04-11 23:17:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cicd_workflows = {
|
|
|
|
for k, v in local.cicd_repositories : k => templatefile(
|
|
|
|
"${path.module}/templates/workflow-${v.type}.yaml",
|
|
|
|
merge(local.cicd_workflow_attrs[k], {
|
2022-06-16 12:56:48 -07:00
|
|
|
identity_provider = try(
|
|
|
|
local.identity_providers[v.identity_provider].name, null
|
|
|
|
)
|
|
|
|
outputs_bucket = var.automation.outputs_bucket
|
|
|
|
stage_name = k
|
2022-04-11 23:17:27 -07:00
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2022-02-15 15:35:50 -08:00
|
|
|
folder_ids = merge(
|
|
|
|
{
|
2022-06-30 09:22:57 -07:00
|
|
|
data-platform-dev = try(module.branch-dp-dev-folder.0.id, null)
|
|
|
|
data-platform-prod = try(module.branch-dp-prod-folder.0.id, null)
|
|
|
|
gke-dev = try(module.branch-gke-dev-folder.0.id, null)
|
|
|
|
gke-prod = try(module.branch-gke-prod-folder.0.id, null)
|
|
|
|
networking = module.branch-network-folder.id
|
|
|
|
networking-dev = module.branch-network-dev-folder.id
|
|
|
|
networking-prod = module.branch-network-prod-folder.id
|
|
|
|
sandbox = try(module.branch-sandbox-folder.0.id, null)
|
|
|
|
security = module.branch-security-folder.id
|
|
|
|
teams = try(module.branch-teams-folder.0.id, null)
|
2022-02-15 15:35:50 -08:00
|
|
|
},
|
|
|
|
{
|
2022-04-11 23:17:27 -07:00
|
|
|
for k, v in module.branch-teams-team-folder :
|
|
|
|
"team-${k}" => v.id
|
2022-02-15 15:35:50 -08:00
|
|
|
},
|
|
|
|
{
|
2022-04-11 23:17:27 -07:00
|
|
|
for k, v in module.branch-teams-team-dev-folder :
|
|
|
|
"team-${k}-dev" => v.id
|
2022-02-15 15:35:50 -08:00
|
|
|
},
|
|
|
|
{
|
2022-04-11 23:17:27 -07:00
|
|
|
for k, v in module.branch-teams-team-prod-folder :
|
|
|
|
"team-${k}-prod" => v.id
|
2022-02-15 15:35:50 -08:00
|
|
|
}
|
|
|
|
)
|
2022-06-28 08:33:37 -07:00
|
|
|
providers = merge(
|
|
|
|
{
|
|
|
|
"02-networking" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-network-gcs.name
|
|
|
|
name = "networking"
|
|
|
|
sa = module.branch-network-sa.email
|
|
|
|
})
|
|
|
|
"02-security" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-security-gcs.name
|
|
|
|
name = "security"
|
|
|
|
sa = module.branch-security-sa.email
|
|
|
|
})
|
|
|
|
},
|
|
|
|
!var.fast_features.data_platform ? {} : {
|
|
|
|
"03-data-platform-dev" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-dp-dev-gcs.0.name
|
|
|
|
name = "dp-dev"
|
|
|
|
sa = module.branch-dp-dev-sa.0.email
|
|
|
|
})
|
|
|
|
"03-data-platform-prod" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-dp-prod-gcs.0.name
|
|
|
|
name = "dp-prod"
|
|
|
|
sa = module.branch-dp-prod-sa.0.email
|
|
|
|
})
|
|
|
|
},
|
2022-06-30 09:22:57 -07:00
|
|
|
!var.fast_features.gke ? {} : {
|
|
|
|
"03-gke-dev" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-gke-dev-gcs.0.name
|
|
|
|
name = "gke-dev"
|
|
|
|
sa = module.branch-gke-dev-sa.0.email
|
|
|
|
})
|
|
|
|
"03-gke-prod" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-gke-prod-gcs.0.name
|
|
|
|
name = "gke-prod"
|
|
|
|
sa = module.branch-gke-prod-sa.0.email
|
|
|
|
})
|
|
|
|
},
|
2022-06-28 08:33:37 -07:00
|
|
|
!var.fast_features.project_factory ? {} : {
|
|
|
|
"03-project-factory-dev" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-pf-dev-gcs.0.name
|
|
|
|
name = "team-dev"
|
|
|
|
sa = module.branch-pf-dev-sa.0.email
|
|
|
|
})
|
|
|
|
"03-project-factory-prod" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-pf-prod-gcs.0.name
|
|
|
|
name = "team-prod"
|
|
|
|
sa = module.branch-pf-prod-sa.0.email
|
|
|
|
})
|
|
|
|
},
|
|
|
|
!var.fast_features.sandbox ? {} : {
|
|
|
|
"99-sandbox" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-sandbox-gcs.0.name
|
|
|
|
name = "sandbox"
|
|
|
|
sa = module.branch-sandbox-sa.0.email
|
|
|
|
})
|
2022-08-03 07:34:09 -07:00
|
|
|
},
|
|
|
|
!var.fast_features.teams ? {} : merge(
|
|
|
|
{
|
|
|
|
"03-teams" = templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-teams-gcs.0.name
|
|
|
|
name = "teams"
|
|
|
|
sa = module.branch-teams-sa.0.email
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
for k, v in module.branch-teams-team-sa :
|
|
|
|
"03-teams-${k}" => templatefile(local._tpl_providers, {
|
|
|
|
bucket = module.branch-teams-team-gcs[k].name
|
|
|
|
name = "teams"
|
|
|
|
sa = v.email
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
2022-06-28 08:33:37 -07:00
|
|
|
)
|
2022-02-15 15:35:50 -08:00
|
|
|
service_accounts = merge(
|
|
|
|
{
|
2022-06-28 08:33:37 -07:00
|
|
|
data-platform-dev = try(module.branch-dp-dev-sa.0.email, null)
|
|
|
|
data-platform-prod = try(module.branch-dp-prod-sa.0.email, null)
|
2022-07-12 03:10:39 -07:00
|
|
|
gke-dev = try(module.branch-gke-dev-sa.0.email, null)
|
|
|
|
gke-prod = try(module.branch-gke-prod-sa.0.email, null)
|
2022-02-15 15:35:50 -08:00
|
|
|
networking = module.branch-network-sa.email
|
2022-06-28 08:33:37 -07:00
|
|
|
project-factory-dev = try(module.branch-pf-dev-sa.0.email, null)
|
|
|
|
project-factory-prod = try(module.branch-pf-prod-sa.0.email, null)
|
|
|
|
sandbox = try(module.branch-sandbox-sa.0.email, null)
|
2022-02-15 15:35:50 -08:00
|
|
|
security = module.branch-security-sa.email
|
2022-08-03 07:34:09 -07:00
|
|
|
teams = try(module.branch-teams-sa.0.email, null)
|
2022-02-15 15:35:50 -08:00
|
|
|
},
|
|
|
|
{
|
2022-02-16 01:57:54 -08:00
|
|
|
for k, v in module.branch-teams-team-sa : "team-${k}" => v.email
|
2022-02-15 15:35:50 -08:00
|
|
|
},
|
|
|
|
)
|
2022-01-19 05:17:20 -08:00
|
|
|
tfvars = {
|
2022-02-16 00:07:07 -08:00
|
|
|
folder_ids = local.folder_ids
|
|
|
|
service_accounts = local.service_accounts
|
2022-04-13 01:22:33 -07:00
|
|
|
tag_names = var.tag_names
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 23:17:27 -07:00
|
|
|
output "cicd_repositories" {
|
|
|
|
description = "WIF configuration for CI/CD repositories."
|
|
|
|
value = {
|
|
|
|
for k, v in local.cicd_repositories : k => {
|
2022-06-15 17:12:11 -07:00
|
|
|
branch = v.branch
|
|
|
|
name = v.name
|
|
|
|
provider = try(
|
|
|
|
local.identity_providers[v.identity_provider].name, null
|
|
|
|
)
|
2022-04-11 23:17:27 -07:00
|
|
|
service_account = local.cicd_workflow_attrs[k].service_account
|
|
|
|
} if v != null
|
|
|
|
}
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
|
2022-02-14 14:54:53 -08:00
|
|
|
output "dataplatform" {
|
|
|
|
description = "Data for the Data Platform stage."
|
2022-06-28 08:33:37 -07:00
|
|
|
value = !var.fast_features.data_platform ? {} : {
|
2022-02-14 14:54:53 -08:00
|
|
|
dev = {
|
2022-06-28 08:33:37 -07:00
|
|
|
folder = module.branch-dp-dev-folder.0.id
|
|
|
|
gcs_bucket = module.branch-dp-dev-gcs.0.name
|
|
|
|
service_account = module.branch-dp-dev-sa.0.email
|
2022-02-14 14:54:53 -08:00
|
|
|
}
|
|
|
|
prod = {
|
2022-06-28 08:33:37 -07:00
|
|
|
folder = module.branch-dp-prod-folder.0.id
|
|
|
|
gcs_bucket = module.branch-dp-prod-gcs.0.name
|
|
|
|
service_account = module.branch-dp-prod-sa.0.email
|
2022-02-14 14:54:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 05:17:20 -08:00
|
|
|
output "networking" {
|
|
|
|
description = "Data for the networking stage."
|
|
|
|
value = {
|
|
|
|
folder = module.branch-network-folder.id
|
|
|
|
gcs_bucket = module.branch-network-gcs.name
|
|
|
|
service_account = module.branch-network-sa.iam_email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output "project_factories" {
|
|
|
|
description = "Data for the project factories stage."
|
2022-06-28 08:33:37 -07:00
|
|
|
value = !var.fast_features.project_factory ? {} : {
|
2022-01-19 05:17:20 -08:00
|
|
|
dev = {
|
2022-06-28 08:33:37 -07:00
|
|
|
bucket = module.branch-pf-dev-gcs.0.name
|
|
|
|
sa = module.branch-pf-dev-sa.0.email
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
prod = {
|
2022-06-28 08:33:37 -07:00
|
|
|
bucket = module.branch-pf-prod-gcs.0.name
|
|
|
|
sa = module.branch-pf-prod-sa.0.email
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ready to use provider configurations for subsequent stages
|
|
|
|
|
|
|
|
output "providers" {
|
2022-02-14 14:54:53 -08:00
|
|
|
# tfdoc:output:consumers 02-networking 02-security 03-dataplatform xx-sandbox xx-teams
|
2022-01-19 05:17:20 -08:00
|
|
|
description = "Terraform provider files for this stage and dependent stages."
|
|
|
|
sensitive = true
|
|
|
|
value = local.providers
|
|
|
|
}
|
|
|
|
|
|
|
|
output "sandbox" {
|
|
|
|
# tfdoc:output:consumers xx-sandbox
|
|
|
|
description = "Data for the sandbox stage."
|
2022-06-28 08:33:37 -07:00
|
|
|
value = (
|
|
|
|
var.fast_features.sandbox
|
|
|
|
? {
|
|
|
|
folder = module.branch-sandbox-folder.0.id
|
|
|
|
gcs_bucket = module.branch-sandbox-gcs.0.name
|
|
|
|
service_account = module.branch-sandbox-sa.0.email
|
|
|
|
}
|
|
|
|
: null
|
|
|
|
)
|
2022-01-19 05:17:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
output "security" {
|
|
|
|
# tfdoc:output:consumers 02-security
|
|
|
|
description = "Data for the networking stage."
|
|
|
|
value = {
|
|
|
|
folder = module.branch-security-folder.id
|
|
|
|
gcs_bucket = module.branch-security-gcs.name
|
|
|
|
service_account = module.branch-security-sa.iam_email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 08:26:43 -08:00
|
|
|
output "gke_multitenant" {
|
|
|
|
# tfdoc:output:consumers 03-gke-multitenant
|
|
|
|
description = "Data for the GKE multitenant stage."
|
2022-06-30 09:22:57 -07:00
|
|
|
value = (
|
|
|
|
var.fast_features.gke
|
|
|
|
? {
|
|
|
|
"dev" = {
|
|
|
|
folder = module.branch-gke-dev-folder.0.id
|
|
|
|
gcs_bucket = module.branch-gke-dev-gcs.0.name
|
|
|
|
service_account = module.branch-gke-dev-sa.0.email
|
|
|
|
}
|
|
|
|
"prod" = {
|
|
|
|
folder = module.branch-gke-prod-folder.0.id
|
|
|
|
gcs_bucket = module.branch-gke-prod-gcs.0.name
|
|
|
|
service_account = module.branch-gke-prod-sa.0.email
|
|
|
|
}
|
2022-02-04 08:26:43 -08:00
|
|
|
}
|
2022-06-30 09:22:57 -07:00
|
|
|
: {}
|
|
|
|
)
|
2022-02-04 08:26:43 -08:00
|
|
|
}
|
|
|
|
|
2022-01-19 05:17:20 -08:00
|
|
|
output "teams" {
|
|
|
|
description = "Data for the teams stage."
|
|
|
|
value = {
|
|
|
|
for k, v in module.branch-teams-team-folder : k => {
|
|
|
|
folder = v.id
|
|
|
|
gcs_bucket = module.branch-teams-team-gcs[k].name
|
|
|
|
service_account = module.branch-teams-team-sa[k].email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# ready to use variable values for subsequent stages
|
|
|
|
|
|
|
|
output "tfvars" {
|
|
|
|
description = "Terraform variable files for the following stages."
|
|
|
|
sensitive = true
|
|
|
|
value = local.tfvars
|
|
|
|
}
|