Simplify #1836 fix, Avoid map-related casting errors in project factory

This commit is contained in:
Wiktor Niesiobędzki 2023-11-02 08:43:06 +00:00
parent de0325b3a3
commit 2664161c24
1 changed files with 11 additions and 12 deletions

View File

@ -15,18 +15,17 @@
*/ */
locals { locals {
# turn the set of file names into a list for index-based access later on _data = (
_factory_files = [ {
for f in fileset("${pathexpand(var.factory_data_path)}", "**/*.yaml") : f for f in fileset(local._data_path, "**/*.yaml") :
] trimsuffix(f, ".yaml") => yamldecode(file("${local._data_path}/${f}"))
# use a list to store data to avoid map enforcing the same type for all }
_factory_data = [ )
for f in local._factory_files : _data_path = var.factory_data_path == null ? null : pathexpand(
yamldecode(file("${pathexpand(var.factory_data_path)}/${f}")) var.factory_data_path
] )
# assemble final data, emulating optionals and using defaults and merges
projects = { projects = {
for i, v in local._factory_data : trimsuffix(local._factory_files[i], ".yaml") => { for k, v in local._data : k => merge(v, {
billing_account = try(coalesce( billing_account = try(coalesce(
var.data_overrides.billing_account, var.data_overrides.billing_account,
try(v.billing_account, null), try(v.billing_account, null),
@ -95,7 +94,7 @@ locals {
try(v.service_accounts, null), try(v.service_accounts, null),
var.data_defaults.service_accounts var.data_defaults.service_accounts
) )
} })
} }
service_accounts = flatten([ service_accounts = flatten([
for k, v in local.projects : [ for k, v in local.projects : [