diff --git a/.tools/test/stacks/config/targets.ts b/.tools/test/stacks/config/targets.ts index 3ae00bfd51e..c2432c88295 100644 --- a/.tools/test/stacks/config/targets.ts +++ b/.tools/test/stacks/config/targets.ts @@ -10,7 +10,11 @@ interface AccountConfig { // https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html vcpus?: string; // Count memory?: string; // MiB, but limited based on vCPU count, see docs - storage?: string; // GiB, 20GiB to 200GiB + storage?: number; // GiB, 20GiB to 200GiB +} + +type AccountConfigYaml = { + [K in keyof AccountConfig]: string } interface AccountConfigs { @@ -20,13 +24,27 @@ interface AccountConfigs { export function readAccountConfig(filePath: string): AccountConfigs { try { const fileContents = fs.readFileSync(filePath, "utf8"); - const data: AccountConfigs = parse(fileContents); - - Object.values(data).forEach((config) => { - if (!config.account_id || !config.status) { - throw new Error("Validation failed: Missing required account fields."); + const data = Object.entries(parse(fileContents) as Record).reduce((data, [name, config]) => { + const {account_id, status, vcpus, memory, storage} = config; + if (!account_id) { + throw new Error(`Validation failed: Missing account_id field in ${name}`); + } + switch (status) { + case "enabled": // fallthrough + case "disabled": + break; + default: + throw new Error(`Validation failed: invalid status ${status} in ${name}`) } - }); + data[name] = { + account_id, + status, + vcpus, + memory, + storage: numberOrDefault(storage, 20), + } + return data; + }, {} as Record) return data; } catch (error) { @@ -34,3 +52,10 @@ export function readAccountConfig(filePath: string): AccountConfigs { throw error; } } + +function numberOrDefault(storage: string | undefined, defaultValue: number) { + const batchStorage = Number(storage); + const batchStorageNumber = isNaN(batchStorage) ? defaultValue : batchStorage; + return batchStorageNumber; +} + diff --git a/.tools/test/stacks/plugin/typescript/plugin_stack.ts b/.tools/test/stacks/plugin/typescript/plugin_stack.ts index 33d6b341dbe..c1f29d8bd26 100644 --- a/.tools/test/stacks/plugin/typescript/plugin_stack.ts +++ b/.tools/test/stacks/plugin/typescript/plugin_stack.ts @@ -24,7 +24,7 @@ class PluginStack extends cdk.Stack { private adminAccountId: string; private batchMemory: string; private batchVcpus: string; - private batchStorage: string; + private batchStorage: number; constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); @@ -44,7 +44,7 @@ class PluginStack extends cdk.Stack { // https://docs.aws.amazon.com/batch/latest/APIReference/API_ResourceRequirement.html this.batchMemory = acctConfig[`${toolName}`]?.memory ?? "16384"; // MiB this.batchVcpus = acctConfig[`${toolName}`]?.vcpus ?? "4"; // CPUs - this.batchStorage = acctConfig[`${toolName}`]?.storage ?? "20"; // GiB + this.batchStorage = acctConfig[`${toolName}`]?.storage ?? 20; // GiB } const [jobDefinition, jobQueue] = this.initBatchFargate();