Skip to content

Commit

Permalink
feat(ec2): add availabilityZoneId support for subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
philcali committed May 28, 2024
1 parent 4bf6fad commit 64cf467
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/aws-cdk-lib/aws-ec2/lib/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Construct, Dependable, DependencyGroup, IConstruct, IDependable, Node }
import { ClientVpnEndpoint, ClientVpnEndpointOptions } from './client-vpn-endpoint';
import {
CfnEIP, CfnEgressOnlyInternetGateway, CfnInternetGateway, CfnNatGateway, CfnRoute, CfnRouteTable, CfnSubnet,
CfnSubnetProps,
CfnSubnetRouteTableAssociation, CfnVPC, CfnVPCCidrBlock, CfnVPCGatewayAttachment, CfnVPNGatewayRoutePropagation,
} from './ec2.generated';
import { AllocatedSubnet, IIpAddresses, RequestedSubnet, IpAddresses, IIpv6Addresses, Ipv6Addresses } from './ip-addresses';
Expand Down Expand Up @@ -1997,6 +1998,13 @@ export interface SubnetProps {
* @default false
*/
readonly assignIpv6AddressOnCreation?: boolean;

/**
* Indicates whether the provided availabilityZone is the id value (ie: use2-az2 for us-east-2b).
*
* @default false
*/
readonly availabilityZoneAsId?: boolean;
}

/**
Expand Down Expand Up @@ -2088,14 +2096,25 @@ export class Subnet extends Resource implements ISubnet {

this.availabilityZone = props.availabilityZone;
this.ipv4CidrBlock = props.cidrBlock;
const subnet = new CfnSubnet(this, 'Subnet', {
let subnetProps: CfnSubnetProps = {
vpcId: props.vpcId,
cidrBlock: props.cidrBlock,
availabilityZone: props.availabilityZone,
mapPublicIpOnLaunch: props.mapPublicIpOnLaunch,
ipv6CidrBlock: props.ipv6CidrBlock,
assignIpv6AddressOnCreation: props.assignIpv6AddressOnCreation,
});
};
if (props.availabilityZoneAsId === true) {
subnetProps = {
...subnetProps,
availabilityZoneId: props.availabilityZone,
};
} else {
subnetProps = {
...subnetProps,
availabilityZone: props.availabilityZone,
};
}
const subnet = new CfnSubnet(this, 'Subnet', subnetProps);
this.subnetId = subnet.ref;
this.subnetVpcId = subnet.attrVpcId;
this.subnetAvailabilityZone = subnet.attrAvailabilityZone;
Expand Down

0 comments on commit 64cf467

Please sign in to comment.