Skip to content

Commit 3d13d2e

Browse files
committed
move splitting of IPv6 CIDRs to ip-addresses
1 parent 2e41fdb commit 3d13d2e

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

packages/aws-cdk-lib/aws-ec2/lib/ip-addresses.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export interface AllocateCidrRequest {
138138
}
139139

140140
/**
141-
* Request for subnet IPv6 CIDRs to be allocated for a VPC
141+
* Request for subnet IPv6 CIDRs to be allocated for a VPC.
142142
*/
143143
export interface AllocateIpv6CidrRequest {
144144
/**
@@ -152,6 +152,27 @@ export interface AllocateIpv6CidrRequest {
152152
readonly ipv6Cidrs: string[];
153153
}
154154

155+
/**
156+
* Request for IPv6 CIDR block to be split up.
157+
*/
158+
export interface CreateIpv6CidrBlocksRequest {
159+
/**
160+
* The IPv6 CIDR block string representation.
161+
*/
162+
readonly ipv6SelectedCidr: string,
163+
164+
/**
165+
* The number of subnets to assign CIDRs to.
166+
*/
167+
readonly subnetCount: number,
168+
169+
/**
170+
* Size of the covered bits in the CIDR.
171+
* @default - 128 - 64 = /64 CIDR.
172+
*/
173+
readonly sizeMask?: string,
174+
}
175+
155176
/**
156177
* CIDR Allocated Subnets
157178
*/
@@ -421,6 +442,13 @@ export interface IIpv6Addresses {
421442
* Note this is specific to the IPv6 CIDR.
422443
*/
423444
allocateSubnetsIpv6Cidr(input: AllocateIpv6CidrRequest): SubnetIpamOptions;
445+
446+
/**
447+
* Split IPv6 CIDR block up for subnets.
448+
*
449+
* Note this is specific to the IPv6 CIDR.
450+
*/
451+
createIpv6CidrBlocks(input: CreateIpv6CidrBlocksRequest): string[];
424452
}
425453

426454
/**
@@ -461,4 +489,17 @@ class AmazonProvided implements IIpv6Addresses {
461489
allocatedSubnets: allocatedSubnets,
462490
};
463491
}
492+
493+
/**
494+
* Split IPv6 CIDR block up for subnets.
495+
*
496+
* Called by VPC when creating subnets with IPv6 enabled.
497+
*
498+
* Note this is specific to the IPv6 CIDR.
499+
*/
500+
createIpv6CidrBlocks(input: CreateIpv6CidrBlocksRequest): string[] {
501+
const sizeMask = input.sizeMask ?? '64'; // 128 - 64
502+
503+
return Fn.cidr(input.ipv6SelectedCidr, input.subnetCount, sizeMask);
504+
}
464505
}

packages/aws-cdk-lib/aws-ec2/lib/vpc.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,10 @@ export class Vpc extends VpcBase {
17841784
throw new Error('No IPv6 IpAddresses were found');
17851785
}
17861786
// create the IPv6 CIDR blocks
1787-
const subnetIpv6Cidrs = Fn.cidr(this.ipv6SelectedCidr, allocatedSubnets.length, (128 - 64).toString());
1787+
const subnetIpv6Cidrs = this.ipv6Addresses.createIpv6CidrBlocks({
1788+
ipv6SelectedCidr: this.ipv6SelectedCidr,
1789+
subnetCount: allocatedSubnets.length,
1790+
});
17881791

17891792
// copy the list of allocated subnets while assigning the IPv6 CIDR
17901793
const allocatedSubnetsIpv6 = this.ipv6Addresses.allocateSubnetsIpv6Cidr({

0 commit comments

Comments
 (0)