Skip to content

Commit

Permalink
move splitting of IPv6 CIDRs to ip-addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
scanlonp committed Jan 11, 2024
1 parent 2e41fdb commit 3d13d2e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
43 changes: 42 additions & 1 deletion packages/aws-cdk-lib/aws-ec2/lib/ip-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export interface AllocateCidrRequest {
}

/**
* Request for subnet IPv6 CIDRs to be allocated for a VPC
* Request for subnet IPv6 CIDRs to be allocated for a VPC.
*/
export interface AllocateIpv6CidrRequest {
/**
Expand All @@ -152,6 +152,27 @@ export interface AllocateIpv6CidrRequest {
readonly ipv6Cidrs: string[];
}

/**
* Request for IPv6 CIDR block to be split up.
*/
export interface CreateIpv6CidrBlocksRequest {
/**
* The IPv6 CIDR block string representation.
*/
readonly ipv6SelectedCidr: string,

/**
* The number of subnets to assign CIDRs to.
*/
readonly subnetCount: number,

/**
* Size of the covered bits in the CIDR.
* @default - 128 - 64 = /64 CIDR.
*/
readonly sizeMask?: string,
}

/**
* CIDR Allocated Subnets
*/
Expand Down Expand Up @@ -421,6 +442,13 @@ export interface IIpv6Addresses {
* Note this is specific to the IPv6 CIDR.
*/
allocateSubnetsIpv6Cidr(input: AllocateIpv6CidrRequest): SubnetIpamOptions;

/**
* Split IPv6 CIDR block up for subnets.
*
* Note this is specific to the IPv6 CIDR.
*/
createIpv6CidrBlocks(input: CreateIpv6CidrBlocksRequest): string[];
}

/**
Expand Down Expand Up @@ -461,4 +489,17 @@ class AmazonProvided implements IIpv6Addresses {
allocatedSubnets: allocatedSubnets,
};
}

/**
* Split IPv6 CIDR block up for subnets.
*
* Called by VPC when creating subnets with IPv6 enabled.
*
* Note this is specific to the IPv6 CIDR.
*/
createIpv6CidrBlocks(input: CreateIpv6CidrBlocksRequest): string[] {
const sizeMask = input.sizeMask ?? '64'; // 128 - 64

return Fn.cidr(input.ipv6SelectedCidr, input.subnetCount, sizeMask);
}
}
5 changes: 4 additions & 1 deletion packages/aws-cdk-lib/aws-ec2/lib/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,10 @@ export class Vpc extends VpcBase {
throw new Error('No IPv6 IpAddresses were found');
}
// create the IPv6 CIDR blocks
const subnetIpv6Cidrs = Fn.cidr(this.ipv6SelectedCidr, allocatedSubnets.length, (128 - 64).toString());
const subnetIpv6Cidrs = this.ipv6Addresses.createIpv6CidrBlocks({
ipv6SelectedCidr: this.ipv6SelectedCidr,
subnetCount: allocatedSubnets.length,
});

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

0 comments on commit 3d13d2e

Please sign in to comment.