From 50ba17a55f2453de7a2248b252c05e1dc41e21d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20B=C3=A9gin?= Date: Mon, 5 May 2025 15:33:02 -0400 Subject: [PATCH 1/2] add sourceIpamPoolId to alpha pool construct --- packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts | 8 +++ .../@aws-cdk/aws-ec2-alpha/test/ipam.test.ts | 71 ++++++++++++------- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts b/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts index 2d84830103727..eab2d247270bd 100644 --- a/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts +++ b/packages/@aws-cdk/aws-ec2-alpha/lib/ipam.ts @@ -144,6 +144,12 @@ export interface PoolOptions { * @default - autogenerated by CDK if not provided */ readonly ipamPoolName?: string; + + /** + * The ID of the source IPAM pool. Use this option to create a pool within an existing pool. + * @default - Pool is created at the top level. + */ + readonly sourceIpamPoolId?: string; } const NAME_TAG: string = 'Name'; @@ -359,6 +365,7 @@ class IpamPool extends Resource implements IIpamPool { ipamScopeId: props.ipamScopeId, publicIpSource: props.publicIpSource, awsService: props.awsService, + sourceIpamPoolId: props.sourceIpamPoolId, }); this.ipamPoolId = this._ipamPool.attrIpamPoolId; @@ -594,5 +601,6 @@ function createIpamPool( locale: poolOptions.locale, publicIpSource: poolOptions.publicIpSource, awsService: poolOptions.awsService, + sourceIpamPoolId: poolOptions.sourceIpamPoolId, }); } 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 46d5f27ebdbc3..aab2de77ded5d 100644 --- a/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts +++ b/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts @@ -77,6 +77,27 @@ describe('IPAM Test', () => { ); // End Template }); + test('Creates nested IP Pools', () => { + const pool = ipam.privateScope.addPool('Private', { + addressFamily: vpc.AddressFamily.IP_V4, + ipv4ProvisionedCidrs: ['10.2.0.0/14'], + locale: 'us-west-2', + }); + ipam.privateScope.addPool('PrivateChild', { + addressFamily: vpc.AddressFamily.IP_V4, + ipv4ProvisionedCidrs: ['10.2.0.0/16'], + sourceIpamPoolId: pool.ipamPoolId, + }); + + Template.fromStack(stack).hasResourceProperties( + 'AWS::EC2::IPAMPool', + { + AddressFamily: 'ipv4', + SourceIpamPoolId: { 'Fn::GetAtt': ['IpamPrivate4E8D7A02', 'IpamPoolId'] }, + }, + ); + }); + test('Creates IPAM CIDR pool under public scope for IPv6', () => { // Create IPAM resources const ipamIpv6 = new Ipam(stack, 'TestIpam', { @@ -182,12 +203,12 @@ describe('IPAM Test', () => { }); Template.fromStack(stack_new).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: 'us-west-2', - }, - ], - }, + OperatingRegions: [ + { + RegionName: 'us-west-2', + }, + ], + }, ); }); @@ -201,12 +222,12 @@ describe('IPAM Test', () => { new Ipam(stack_new, 'TestIpam', {}); Template.fromStack(stack_new).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: 'us-west-2', - }, - ], - }, + OperatingRegions: [ + { + RegionName: 'us-west-2', + }, + ], + }, ); }); @@ -216,14 +237,14 @@ describe('IPAM Test', () => { new Ipam(stack_new, 'TestIpam', {}); Template.fromStack(stack_new).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: { - Ref: 'AWS::Region', - }, + OperatingRegions: [ + { + RegionName: { + Ref: 'AWS::Region', }, - ], - }, + }, + ], + }, ); }); @@ -254,12 +275,12 @@ describe('IPAM Test', () => { new Ipam(testStack, 'TestIpamNew', {}); Template.fromStack(testStack).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: 'us-west-1', - }, - ], - }, + OperatingRegions: [ + { + RegionName: 'us-west-1', + }, + ], + }, ); }); });// End Test From 18e18992e147761f6dc1a275921dadc2bc3be75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20B=C3=A9gin?= Date: Mon, 5 May 2025 15:38:26 -0400 Subject: [PATCH 2/2] formatting --- .../@aws-cdk/aws-ec2-alpha/test/ipam.test.ts | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) 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 aab2de77ded5d..caece1016dbe7 100644 --- a/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts +++ b/packages/@aws-cdk/aws-ec2-alpha/test/ipam.test.ts @@ -203,12 +203,12 @@ describe('IPAM Test', () => { }); Template.fromStack(stack_new).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: 'us-west-2', - }, - ], - }, + OperatingRegions: [ + { + RegionName: 'us-west-2', + }, + ], + }, ); }); @@ -222,12 +222,12 @@ describe('IPAM Test', () => { new Ipam(stack_new, 'TestIpam', {}); Template.fromStack(stack_new).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: 'us-west-2', - }, - ], - }, + OperatingRegions: [ + { + RegionName: 'us-west-2', + }, + ], + }, ); }); @@ -237,14 +237,14 @@ describe('IPAM Test', () => { new Ipam(stack_new, 'TestIpam', {}); Template.fromStack(stack_new).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: { - Ref: 'AWS::Region', + OperatingRegions: [ + { + RegionName: { + Ref: 'AWS::Region', + }, }, - }, - ], - }, + ], + }, ); }); @@ -275,12 +275,12 @@ describe('IPAM Test', () => { new Ipam(testStack, 'TestIpamNew', {}); Template.fromStack(testStack).hasResourceProperties( 'AWS::EC2::IPAM', { - OperatingRegions: [ - { - RegionName: 'us-west-1', - }, - ], - }, + OperatingRegions: [ + { + RegionName: 'us-west-1', + }, + ], + }, ); }); });// End Test