Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-ec2): change maxAZs default for VPCs to 3 #1543

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indicate what users should do if they want to use all AZs (even if it's "99")

*/
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