in packages/@aws-cdk/toolkit-lib/lib/context-providers/vpcs.ts [174:252]
publicSubnetIds: collapse(
flatMap(findGroups(SubnetType.Public, grouped), (group) => group.subnets.map((s) => s.subnetId)),
),
publicSubnetNames: collapse(
flatMap(findGroups(SubnetType.Public, grouped), (group) => (group.name ? [group.name] : [])),
),
publicSubnetRouteTableIds: collapse(
flatMap(findGroups(SubnetType.Public, grouped), (group) => group.subnets.map((s) => s.routeTableId)),
),
vpnGatewayId,
subnetGroups: assymetricSubnetGroups,
};
}
}
class RouteTables {
public readonly mainRouteTable?: RouteTable;
constructor(private readonly tables: RouteTable[]) {
this.mainRouteTable = this.tables.find(
(table) => !!table.Associations && table.Associations.some((assoc) => !!assoc.Main),
);
}
public routeTableIdForSubnetId(subnetId: string | undefined): string | undefined {
const table = this.tableForSubnet(subnetId);
return (table && table.RouteTableId) || (this.mainRouteTable && this.mainRouteTable.RouteTableId);
}
/**
* Whether the given subnet has a route to a NAT Gateway
*/
public hasRouteToNatGateway(subnetId: string | undefined): boolean {
const table = this.tableForSubnet(subnetId) || this.mainRouteTable;
return (
!!table &&
!!table.Routes &&
table.Routes.some((route) => !!route.NatGatewayId && route.DestinationCidrBlock === '0.0.0.0/0')
);
}
/**
* Whether the given subnet has a route to a Transit Gateway
*/
public hasRouteToTransitGateway(subnetId: string | undefined): boolean {
const table = this.tableForSubnet(subnetId) || this.mainRouteTable;
return (
!!table &&
!!table.Routes &&
table.Routes.some((route) => !!route.TransitGatewayId && route.DestinationCidrBlock === '0.0.0.0/0')
);
}
/**
* Whether the given subnet has a route to an IGW
*/
public hasRouteToIgw(subnetId: string | undefined): boolean {
const table = this.tableForSubnet(subnetId) || this.mainRouteTable;
return (
!!table && !!table.Routes && table.Routes.some((route) => !!route.GatewayId && route.GatewayId.startsWith('igw-'))
);
}
public tableForSubnet(subnetId: string | undefined) {
return this.tables.find(
(table) => !!table.Associations && table.Associations.some((assoc) => assoc.SubnetId === subnetId),
);
}
}
/**
* Return the value of a tag from a set of tags
*/
function getTag(name: string, tags?: Tag[]): string | undefined {
for (const tag of tags || []) {
if (tag.Key === name) {