Skip to content

Commit

Permalink
addressing last feedback comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shikha372 committed Jun 14, 2024
1 parent 7b9885f commit a025665
Show file tree
Hide file tree
Showing 20 changed files with 1,808 additions and 56 deletions.
67 changes: 41 additions & 26 deletions packages/@aws-cdk/aws-vpcv2-alpha/lib/ipam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ function getAddressFamilyString(addressFamily: AddressFamily): string {
}
}

export interface CfnPoolOptions extends PoolOptions {
readonly ipamScopeId: string;
}

export interface PoolOptions{
readonly addressFamily: AddressFamily;
readonly provisionedCidrs: CfnIPAMPool.ProvisionedCidrProperty[];
readonly region?: string;
readonly locale?: string;
}

export interface IpamScopeOptions {
readonly ipamID: string;
readonly ipamId: string;
}

export interface IpamOptions {
Expand Down Expand Up @@ -60,6 +64,23 @@ export interface IpamOptions {
readonly ipv6IpamPoolId?: string;
}

export class IpamPool {

public readonly ipamPoolId: string;
public readonly pool: CfnIPAMPool;
constructor(scope: Construct, id: string, options: CfnPoolOptions) {

const CfnPool = new CfnIPAMPool(scope, id, {
addressFamily: getAddressFamilyString(options.addressFamily),
provisionedCidrs: options.provisionedCidrs,
locale: options.locale,
ipamScopeId: options.ipamScopeId,
});
this.ipamPoolId = CfnPool.attrIpamPoolId;
this.pool = CfnPool;
}
}

export class IpamIpv4 implements IIpAddresses {

constructor(private readonly props: IpamOptions) {
Expand All @@ -85,7 +106,7 @@ export class IpamScope extends Resource {
constructor(scope: Construct, id: string, props: IpamScopeOptions) {
super(scope, id);
this._ipamScope = new CfnIPAMScope(scope, 'IpamScope', {
ipamId: props.ipamID,
ipamId: props.ipamId,
});
this.ipamScopeId = this._ipamScope.attrIpamScopeId;
}
Expand All @@ -103,19 +124,19 @@ export class Ipam {
// Resource IPAM
private readonly _ipam: CfnIPAM;
// can be used later to add a custom private scope
public readonly ipamID: string;
public readonly ipamId: string;
constructor(scope: Construct, id: string) {
this._ipam = new CfnIPAM(scope, id);
this.publicScope = new IpamPublicScope(scope, this._ipam.attrPublicDefaultScopeId);
this.privateScope = new IpamPrivateScope(scope, this._ipam.attrPrivateDefaultScopeId);
this.ipamID = this._ipam.attrIpamId;
this.ipamId = this._ipam.attrIpamId;
}
}

export class IpamPublicScope {

public readonly defaultpublicScopeId: string;
private readonly scope: Construct;
public readonly scope: Construct;

constructor(scope: Construct, id: string) {
this.defaultpublicScopeId = id;
Expand All @@ -126,17 +147,17 @@ export class IpamPublicScope {
* There can be multiple options supported under a scope
* for pool like using amazon provided IPv6
*/
addPool(options: PoolOptions): CfnIPAMPool {
addPool(options: PoolOptions): IpamPool {

/**
* creates pool under default public scope (IPV4, IPV6)
*/
return new CfnIPAMPool(this.scope, 'TestPool', {
addressFamily: getAddressFamilyString(options.addressFamily),
return new IpamPool(this.scope, 'PublicPool', {
addressFamily: options.addressFamily,
provisionedCidrs: options.provisionedCidrs,
ipamScopeId: this.defaultpublicScopeId,
//TODO: should be stack region or props input
locale: options.region,
locale: options.locale,
});
}
}
Expand All @@ -147,7 +168,7 @@ export class IpamPublicScope {

export class IpamPrivateScope {
public readonly defaultprivateScopeId: string;
private readonly scope: Construct;
public readonly scope: Construct;

constructor(scope: Construct, id: string) {
this.defaultprivateScopeId = id;
Expand All @@ -158,28 +179,21 @@ export class IpamPrivateScope {
* There can be multiple options supported under a scope
* for pool like using amazon provided IPv6
*/
addPool(options: PoolOptions): CfnIPAMPool {
addPool(options: PoolOptions):IpamPool {

/**
* creates pool under default public scope (IPV4, IPV6)
*/
return new CfnIPAMPool(this.scope, 'TestPool', {
addressFamily: getAddressFamilyString(options.addressFamily),
return new IpamPool(this.scope, 'PrivatePool', {
addressFamily: options.addressFamily,
provisionedCidrs: options.provisionedCidrs,
ipamScopeId: this.defaultprivateScopeId,
//TODO: should be stack region or props input
locale: options.region,
locale: options.locale,
});
/**
* creates pool under default public scope (IPV4, IPV6)
*/
}
}

//Customer Implementation Example
// const ipam = new Ipam(this, 'Ipam');
// ipam.publicScope.addPool({
// addressFamily: AddressFamily.IP_V4,
// provisionedCidrs: [{ cidr: '10.0.0.0/24' }],
// });

export class IpamIpv6 implements IIpAddresses {

constructor(private readonly props: IpamOptions) {
Expand All @@ -191,4 +205,5 @@ export class IpamIpv6 implements IIpAddresses {
ipv6IpamPoolId: this.props.ipv6IpamPoolId,
};
}
}
}

11 changes: 3 additions & 8 deletions packages/@aws-cdk/aws-vpcv2-alpha/lib/vpc-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,8 @@ function validateIpv4address(cidr1?: string, cidr2?: string): boolean {
octet2: octetsCidr2[1],
};

if (
(ip1.octet1 === 10 && ip2.octet1 === 10) ||
return (ip1.octet1 === 10 && ip2.octet1 === 10) ||
(ip1.octet1 === 192 && ip1.octet2 === 168 && ip2.octet1 === 192 && ip2.octet2 === 168) ||
(ip1.octet1 === 172 && ip1.octet2 === 16 && ip2.octet1 === 172 && ip2.octet2 === 16)
) {
return true; // CIDR ranges belong to same private IP address ranges
} else {
return false;
} // CIDR ranges do not belong to same private IP address ranges
(ip1.octet1 === 172 && ip1.octet2 === 16 && ip2.octet1 === 172 && ip2.octet2 === 16);
return true; // CIDR ranges belong to same private IP address ranges
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"Resources": {
"Ipam": {
"Type": "AWS::EC2::IPAM"
},
"PrivatePool": {
"Type": "AWS::EC2::IPAMPool",
"Properties": {
"AddressFamily": "ipv4",
"IpamScopeId": {
"Fn::GetAtt": [
"Ipam",
"PrivateDefaultScopeId"
]
},
"Locale": "us-west-2",
"ProvisionedCidrs": [
{
"Cidr": "10.2.0.0/16"
}
]
}
},
"VPCTestFB735C86": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsHostnames": true,
"EnableDnsSupport": true
}
},
"VPCTestSecondaryIp1BB4FC62E": {
"Type": "AWS::EC2::VPCCidrBlock",
"Properties": {
"Ipv4IpamPoolId": {
"Fn::GetAtt": [
"PrivatePool",
"IpamPoolId"
]
},
"Ipv4NetmaskLength": 20,
"VpcId": {
"Fn::GetAtt": [
"VPCTestFB735C86",
"VpcId"
]
}
}
},
"VPCTestSecondaryIp24E984B36": {
"Type": "AWS::EC2::VPCCidrBlock",
"Properties": {
"AmazonProvidedIpv6CidrBlock": true,
"VpcId": {
"Fn::GetAtt": [
"VPCTestFB735C86",
"VpcId"
]
}
}
},
"VPCTestVpnGateway51EEED38": {
"Type": "AWS::EC2::VPNGateway",
"Properties": {
"Type": "ipsec.1"
}
},
"VPCTestVPCVPNGW0A869280": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {
"Fn::GetAtt": [
"VPCTestFB735C86",
"VpcId"
]
},
"VpnGatewayId": {
"Ref": "VPCTestVpnGateway51EEED38"
}
}
},
"VPCTestRoutePropagationFEA3011A": {
"Type": "AWS::EC2::VPNGatewayRoutePropagation",
"Properties": {
"RouteTableIds": [
{
"Ref": "testsbubnetRouteTableF40F025B"
}
],
"VpnGatewayId": {
"Ref": "VPCTestVpnGateway51EEED38"
}
},
"DependsOn": [
"VPCTestVPCVPNGW0A869280"
]
},
"testsbubnetSubnet77337845": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": "us-west-2a",
"CidrBlock": "10.0.0.0/24",
"VpcId": {
"Fn::GetAtt": [
"VPCTestFB735C86",
"VpcId"
]
}
}
},
"testsbubnetRouteTableF40F025B": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Fn::GetAtt": [
"VPCTestFB735C86",
"VpcId"
]
}
}
},
"testsbubnetRouteTableAssociationD6D083FA": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"RouteTableId": {
"Ref": "testsbubnetRouteTableF40F025B"
},
"SubnetId": {
"Ref": "testsbubnetSubnet77337845"
}
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a025665

Please sign in to comment.