Skip to content

Commit

Permalink
fix(aws-autoscaling): allow minSize to be set to 0 (#1015)
Browse files Browse the repository at this point in the history
Previously, minSize was being set to `props.minSize || 1`. Since 0 is
falsey in javascript, this would mean 0 passed in through the ASG props
evaluate to false and the field would always be set to the default value
of 1. This change uses strict equality comparison to allow 0 to be set.
  • Loading branch information
SoManyHs authored and rix0rrr committed Oct 29, 2018
1 parent 2219ac9 commit 67f7fa1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ export class AutoScalingGroup extends cdk.Construct implements cdk.ITaggable, el

launchConfig.addDependency(this.role);

const minSize = props.minSize || 1;
const maxSize = props.maxSize || 1;
const desiredCapacity = props.desiredCapacity || 1;
const minSize = props.minSize !== undefined ? props.minSize : 1;
const maxSize = props.maxSize !== undefined ? props.maxSize : 1;
const desiredCapacity = props.desiredCapacity !== undefined ? props.desiredCapacity : 1;

if (desiredCapacity < minSize || desiredCapacity > maxSize) {
throw new Error(`Should have minSize (${minSize}) <= desiredCapacity (${desiredCapacity}) <= maxSize (${maxSize})`);
Expand Down
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ export = {
test.done();
},

'can set minSize, maxSize, desiredCapacity to 0'(test: Test) {
const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }});
const vpc = mockVpc(stack);

new autoscaling.AutoScalingGroup(stack, 'MyFleet', {
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.Micro),
machineImage: new ec2.AmazonLinuxImage(),
vpc,
minSize: 0,
maxSize: 0,
desiredCapacity: 0
});

expect(stack).to(haveResource("AWS::AutoScaling::AutoScalingGroup", {
MinSize: "0",
MaxSize: "0",
DesiredCapacity: "0",
}
));

test.done();
},

'addToRolePolicy can be used to add statements to the role policy'(test: Test) {
const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }});
const vpc = mockVpc(stack);
Expand Down

0 comments on commit 67f7fa1

Please sign in to comment.