diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc.ts b/packages/@aws-cdk/aws-ec2/lib/vpc.ts index 875d22ba24483..93af5eb8ed121 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc.ts @@ -58,7 +58,11 @@ export interface VpcNetworkProps { * If the region has more AZs than you want to use (for example, because of EIP limits), * pick a lower number here. The AZs will be sorted and picked from the start of the list. * - * @default All AZs in the region + * If you pick a higher number than the number of AZs in the region, all AZs in + * the region will be selected. To use "all AZs" available to your account, use a + * high number (such as 99). + * + * @default 3 */ maxAZs?: number; @@ -315,9 +319,9 @@ export class VpcNetwork extends VpcNetworkBase implements cdk.ITaggable { this.availabilityZones = new cdk.AvailabilityZoneProvider(this).availabilityZones; this.availabilityZones.sort(); - if (props.maxAZs != null) { - this.availabilityZones = this.availabilityZones.slice(0, props.maxAZs); - } + + const maxAZs = props.maxAZs !== undefined ? props.maxAZs : 3; + this.availabilityZones = this.availabilityZones.slice(0, maxAZs); this.vpcId = this.resource.vpcId; this.dependencyElements.push(this.resource); @@ -709,4 +713,4 @@ class ImportedVpcSubnet extends cdk.Construct implements IVpcSubnet { public export() { return this.props; } -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts index afa4c91f45177..ec8aa87d1403e 100644 --- a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts +++ b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts @@ -233,6 +233,25 @@ export = { })); test.done(); }, + + "maxAZs defaults to 3 if unset"(test: Test) { + const stack = getTestStack(); + new VpcNetwork(stack, 'VPC'); + expect(stack).to(countResources("AWS::EC2::Subnet", 6)); + expect(stack).to(countResources("AWS::EC2::Route", 6)); + for (let i = 0; i < 6; i++) { + expect(stack).to(haveResource("AWS::EC2::Subnet", { + CidrBlock: `10.0.${i * 32}.0/19` + })); + } + expect(stack).to(haveResourceLike("AWS::EC2::Route", { + DestinationCidrBlock: '0.0.0.0/0', + NatGatewayId: { }, + })); + + test.done(); + }, + "with maxAZs set to 2"(test: Test) { const stack = getTestStack(); new VpcNetwork(stack, 'VPC', { maxAZs: 2 });