From e706ee923834b234492a1d2a2746a69d0d9f57bc Mon Sep 17 00:00:00 2001 From: Jay Kim Date: Thu, 24 Apr 2025 10:58:31 -0700 Subject: [PATCH 1/2] chore: check IPAM Pool local in Operating Region only if specified --- packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts b/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts index 4e27d67183c90..2d84830103727 100644 --- a/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts +++ b/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts @@ -573,13 +573,17 @@ function createIpamPool( poolOptions: PoolOptions, scopeId: string, ): IpamPool { - const isLocaleInOperatingRegions = scopeOptions.ipamOperatingRegions - ? scopeOptions.ipamOperatingRegions.map(region => ({ regionName: region })) - .some(region => region.regionName === poolOptions.locale) - : false; - - if (!isLocaleInOperatingRegions) { - throw new Error(`The provided locale '${poolOptions.locale}' is not in the operating regions.`); + // Only check locale if it's provided since it's an optional field + if (poolOptions.locale) { + const isLocaleInOperatingRegions = scopeOptions.ipamOperatingRegions + ? scopeOptions.ipamOperatingRegions.map(region => ({ regionName: region })) + .some(region => region.regionName === poolOptions.locale) + : false; + + if (!isLocaleInOperatingRegions) { + throw new Error(`The provided locale '${poolOptions.locale}' is not in the operating regions (${scopeOptions.ipamOperatingRegions}). ` + + 'If specified, locale must be configured as an operating region for the IPAM.'); + } } return new IpamPool(scope, id, { @@ -592,4 +596,3 @@ function createIpamPool( awsService: poolOptions.awsService, }); } - From d21837ae42f38b4102190109fbb979a2143ecbbe Mon Sep 17 00:00:00 2001 From: Jay Kim Date: Thu, 24 Apr 2025 14:44:41 -0700 Subject: [PATCH 2/2] chore(ec2-alpha): check IPAM Pool local in Operating Region only if specified --- packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts b/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts index 79a945aba0734..46d5f27ebdbc3 100644 --- a/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts +++ b/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts @@ -237,7 +237,11 @@ describe('IPAM Test', () => { publicIpSource: IpamPoolPublicIpSource.AMAZON, locale: 'us-west-1', // Incorrect Region }; - expect(() => ipamRegion.publicScope.addPool('TestPool', poolOptions)).toThrow("The provided locale 'us-west-1' is not in the operating regions."); + expect(() => ipamRegion.publicScope.addPool('TestPool', poolOptions)) + .toThrow( + `The provided locale 'us-west-1' is not in the operating regions (${ipamRegion.operatingRegions}). ` + + 'If specified, locale must be configured as an operating region for the IPAM.', + ); }); test('IPAM handles operating regions correctly', () => {