in src/main.ts [211:230]
private validateSubnets(vpc: ec2.IVpc, vpcSubnets: ec2.SubnetSelection) {
const subnets = vpc.selectSubnets(vpcSubnets);
// get all subnets in the VPC
const allsubnetIds = vpc.publicSubnets.concat(vpc.privateSubnets).concat(vpc.isolatedSubnets).map(x => x.subnetId);
// validate the given subnets
subnets.subnetIds.forEach(s => {
if (!allsubnetIds.includes(s)) {
throw new Error(`${s} does not exist in the VPC`);
}
if (vpc.isolatedSubnets.map(i => i.subnetId).includes(s)) {
throw new Error(`Isolated subnet ${s} is not allowed`);
}
});
const hasPublic = subnets.subnetIds.some(s => new Set(vpc.publicSubnets.map(x => x.subnetId)).has(s));
const hasPrivate = subnets.subnetIds.some(s => new Set(vpc.privateSubnets.map(x => x.subnetId)).has(s));
if (hasPublic && hasPrivate) {
throw new Error('You should provide either all public or all private subnets, not both.');
}
this.isPublicSubnets = subnets.subnetIds.some(s => new Set(vpc.publicSubnets.map(x => x.subnetId)).has(s));
}