From 39a029fa62c2e4d48c79aea1a9297a90973558d4 Mon Sep 17 00:00:00 2001 From: Olivier Hoareau Date: Mon, 2 Sep 2024 21:25:53 +0200 Subject: [PATCH] fix: add support for multiple providers for different regions --- src/generators/v2.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/generators/v2.ts b/src/generators/v2.ts index 98dd535..97cb941 100644 --- a/src/generators/v2.ts +++ b/src/generators/v2.ts @@ -15,7 +15,6 @@ export default async ( [`data.tf`, replace(s, {...vars, is_data_file: true})], [`locals.tf`, replace(s, {...vars, is_locals_file: true})], [`variables.tf`, replace(s, {...vars, is_variables_file: true})], - [`outputs.tf`, replace(s, {...vars, is_outputs_file: true})], [ `providers.tf`, replace(s, { @@ -35,6 +34,26 @@ export default async ( is_providers_file: true, }) as unknown as string, ], + // region outputs files + ...Object.entries(regions).map( + ([rCode, r]: [string, layer_region_config]) => { + const isDefault = (r?.id || rCode) === defaultRegion; + return [ + `outputs${isDefault ? '' : `_${rCode.replace(/-/g, '_')}`}.tf`, + replace(s, { + ...vars, + region: r?.id || rCode, + is_default_outputs: isDefault, + is_outputs_file: true, + is_default_region: isDefault, + psuffix: isDefault ? '' : `.${rCode}`, + rsuffix: isDefault ? '' : `-${rCode}`, + ...r, + ...(vars?.id ? {id: vars.id} : {}), + }) as unknown as string, + ]; + }, + ), // region main files ...Object.entries(regions).map( ([rCode, r]: [string, layer_region_config]) => {