From 2664161c24a1ff21301425c77b1abab653c3cbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Niesiob=C4=99dzki?= Date: Thu, 2 Nov 2023 08:43:06 +0000 Subject: [PATCH] Simplify #1836 fix, Avoid map-related casting errors in project factory --- .../factories/project-factory/factory.tf | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/blueprints/factories/project-factory/factory.tf b/blueprints/factories/project-factory/factory.tf index b2187f71..eabb551a 100644 --- a/blueprints/factories/project-factory/factory.tf +++ b/blueprints/factories/project-factory/factory.tf @@ -15,18 +15,17 @@ */ locals { - # turn the set of file names into a list for index-based access later on - _factory_files = [ - for f in fileset("${pathexpand(var.factory_data_path)}", "**/*.yaml") : f - ] - # use a list to store data to avoid map enforcing the same type for all - _factory_data = [ - for f in local._factory_files : - yamldecode(file("${pathexpand(var.factory_data_path)}/${f}")) - ] - # assemble final data, emulating optionals and using defaults and merges + _data = ( + { + for f in fileset(local._data_path, "**/*.yaml") : + trimsuffix(f, ".yaml") => yamldecode(file("${local._data_path}/${f}")) + } + ) + _data_path = var.factory_data_path == null ? null : pathexpand( + var.factory_data_path + ) 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( var.data_overrides.billing_account, try(v.billing_account, null), @@ -95,7 +94,7 @@ locals { try(v.service_accounts, null), var.data_defaults.service_accounts ) - } + }) } service_accounts = flatten([ for k, v in local.projects : [