2023-08-20 00:44:20 -07:00
|
|
|
/**
|
|
|
|
* 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 {
|
2024-02-27 10:13:49 -08:00
|
|
|
_project_path = try(pathexpand(var.factories_config.projects_data_path), null)
|
|
|
|
_projects = (
|
2023-11-02 01:43:06 -07:00
|
|
|
{
|
2024-02-27 10:13:49 -08:00
|
|
|
for f in try(fileset(local._project_path, "**/*.yaml"), []) :
|
|
|
|
trimsuffix(f, ".yaml") => yamldecode(file("${local._project_path}/${f}"))
|
2023-11-02 01:43:06 -07:00
|
|
|
}
|
|
|
|
)
|
2024-02-27 10:13:49 -08:00
|
|
|
_project_budgets = flatten([
|
|
|
|
for k, v in local._projects : [
|
|
|
|
for b in try(v.billing_budgets, []) : {
|
|
|
|
budget = b
|
|
|
|
project = k
|
|
|
|
}
|
|
|
|
]
|
|
|
|
])
|
|
|
|
project_budgets = {
|
|
|
|
for v in local._project_budgets : v.budget => v.project...
|
|
|
|
}
|
2023-08-20 00:44:20 -07:00
|
|
|
projects = {
|
2024-02-27 10:13:49 -08:00
|
|
|
for k, v in local._projects : k => merge(v, {
|
2023-09-07 05:48:39 -07:00
|
|
|
billing_account = try(coalesce(
|
2023-08-20 00:44:20 -07:00
|
|
|
var.data_overrides.billing_account,
|
|
|
|
try(v.billing_account, null),
|
|
|
|
var.data_defaults.billing_account
|
2023-09-07 05:48:39 -07:00
|
|
|
), null)
|
2023-08-20 00:44:20 -07:00
|
|
|
contacts = coalesce(
|
|
|
|
var.data_overrides.contacts,
|
|
|
|
try(v.contacts, null),
|
|
|
|
var.data_defaults.contacts
|
|
|
|
)
|
|
|
|
labels = coalesce(
|
|
|
|
try(v.labels, null),
|
|
|
|
var.data_defaults.labels
|
|
|
|
)
|
|
|
|
metric_scopes = coalesce(
|
|
|
|
try(v.metric_scopes, null),
|
|
|
|
var.data_defaults.metric_scopes
|
|
|
|
)
|
2023-10-02 07:13:56 -07:00
|
|
|
org_policies = try(v.org_policies, {})
|
2023-09-07 05:48:39 -07:00
|
|
|
parent = coalesce(
|
|
|
|
var.data_overrides.parent,
|
|
|
|
try(v.parent, null),
|
|
|
|
var.data_defaults.parent
|
|
|
|
)
|
2023-08-20 00:44:20 -07:00
|
|
|
prefix = coalesce(
|
|
|
|
var.data_overrides.prefix,
|
|
|
|
try(v.prefix, null),
|
|
|
|
var.data_defaults.prefix
|
|
|
|
)
|
|
|
|
service_encryption_key_ids = coalesce(
|
|
|
|
var.data_overrides.service_encryption_key_ids,
|
|
|
|
try(v.service_encryption_key_ids, null),
|
|
|
|
var.data_defaults.service_encryption_key_ids
|
|
|
|
)
|
|
|
|
service_perimeter_bridges = coalesce(
|
|
|
|
var.data_overrides.service_perimeter_bridges,
|
|
|
|
try(v.service_perimeter_bridges, null),
|
|
|
|
var.data_defaults.service_perimeter_bridges
|
|
|
|
)
|
|
|
|
service_perimeter_standard = try(coalesce(
|
|
|
|
var.data_overrides.service_perimeter_standard,
|
|
|
|
try(v.service_perimeter_standard, null),
|
|
|
|
var.data_defaults.service_perimeter_standard
|
|
|
|
), null)
|
|
|
|
services = coalesce(
|
|
|
|
var.data_overrides.services,
|
|
|
|
try(v.services, null),
|
|
|
|
var.data_defaults.services
|
|
|
|
)
|
2023-10-23 06:45:48 -07:00
|
|
|
shared_vpc_service_config = (
|
|
|
|
try(v.shared_vpc_service_config, null) != null
|
|
|
|
? merge(
|
2023-12-07 01:07:48 -08:00
|
|
|
{
|
2023-12-15 05:39:21 -08:00
|
|
|
network_users = []
|
2023-12-07 01:07:48 -08:00
|
|
|
service_identity_iam = {}
|
|
|
|
service_identity_subnet_iam = {}
|
|
|
|
service_iam_grants = []
|
2023-12-15 05:39:21 -08:00
|
|
|
network_subnet_users = {}
|
2023-12-07 01:07:48 -08:00
|
|
|
},
|
2023-10-23 06:45:48 -07:00
|
|
|
v.shared_vpc_service_config
|
|
|
|
)
|
|
|
|
: var.data_defaults.shared_vpc_service_config
|
2023-08-20 00:44:20 -07:00
|
|
|
)
|
|
|
|
tag_bindings = coalesce(
|
|
|
|
var.data_overrides.tag_bindings,
|
|
|
|
try(v.tag_bindings, null),
|
|
|
|
var.data_defaults.tag_bindings
|
|
|
|
)
|
|
|
|
# non-project resources
|
2024-03-05 04:13:02 -08:00
|
|
|
service_accounts = try(v.service_accounts, {})
|
2023-11-02 01:43:06 -07:00
|
|
|
})
|
2023-08-20 00:44:20 -07:00
|
|
|
}
|
|
|
|
service_accounts = flatten([
|
|
|
|
for k, v in local.projects : [
|
|
|
|
for name, opts in v.service_accounts : {
|
2024-03-05 04:13:02 -08:00
|
|
|
project = k
|
|
|
|
name = name
|
|
|
|
display_name = coalesce(
|
|
|
|
try(var.data_overrides.service_accounts.display_name, null),
|
|
|
|
try(opts.display_name, null),
|
|
|
|
try(var.data_defaults.service_accounts.display_name, null),
|
|
|
|
"Terraform-managed."
|
|
|
|
)
|
|
|
|
iam_billing_roles = try(opts.iam_billing_roles, {})
|
|
|
|
iam_organization_roles = try(opts.iam_organization_roles, {})
|
|
|
|
iam_sa_roles = try(opts.iam_sa_roles, {})
|
|
|
|
iam_project_roles = try(opts.iam_project_roles, {})
|
|
|
|
iam_self_roles = distinct(concat(
|
|
|
|
try(var.data_overrides.service_accounts.iam_self_roles, []),
|
|
|
|
try(opts.iam_self_roles, []),
|
|
|
|
try(var.data_defaults.service_accounts.iam_self_roles, []),
|
|
|
|
))
|
|
|
|
iam_storage_roles = try(opts.iam_storage_roles, {})
|
|
|
|
opts = opts
|
2023-08-20 00:44:20 -07:00
|
|
|
}
|
|
|
|
]
|
|
|
|
])
|
|
|
|
}
|