Skip to content

Commit

Permalink
fix(aws-ec2): change maxAZs default for VPCs to 3
Browse files Browse the repository at this point in the history
For most users, default deployments of a VPC in `us-east-1` would fail
because that region has more AZs (6) than the allowed EIP allocations in
an acccount (5).

This is a very poor experience. Plus, it is wasteful since there is
not much additional value in using more than 3 AZs for a VPC.

Fixes #996.
  • Loading branch information
rix0rrr committed Jan 14, 2019
1 parent 9d7e050 commit 29d5d5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-ec2/lib/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ 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
* @default 3
*/
maxAZs?: number;

Expand Down Expand Up @@ -315,9 +315,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);
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/test.vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 29d5d5f

Please sign in to comment.