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 : [