Skip to content

Commit 67f7fa1

Browse files
SoManyHsrix0rrr
authored andcommitted
fix(aws-autoscaling): allow minSize to be set to 0 (#1015)
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.
1 parent 2219ac9 commit 67f7fa1

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ export class AutoScalingGroup extends cdk.Construct implements cdk.ITaggable, el
212212

213213
launchConfig.addDependency(this.role);
214214

215-
const minSize = props.minSize || 1;
216-
const maxSize = props.maxSize || 1;
217-
const desiredCapacity = props.desiredCapacity || 1;
215+
const minSize = props.minSize !== undefined ? props.minSize : 1;
216+
const maxSize = props.maxSize !== undefined ? props.maxSize : 1;
217+
const desiredCapacity = props.desiredCapacity !== undefined ? props.desiredCapacity : 1;
218218

219219
if (desiredCapacity < minSize || desiredCapacity > maxSize) {
220220
throw new Error(`Should have minSize (${minSize}) <= desiredCapacity (${desiredCapacity}) <= maxSize (${maxSize})`);

packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ export = {
126126
test.done();
127127
},
128128

129+
'can set minSize, maxSize, desiredCapacity to 0'(test: Test) {
130+
const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }});
131+
const vpc = mockVpc(stack);
132+
133+
new autoscaling.AutoScalingGroup(stack, 'MyFleet', {
134+
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.Micro),
135+
machineImage: new ec2.AmazonLinuxImage(),
136+
vpc,
137+
minSize: 0,
138+
maxSize: 0,
139+
desiredCapacity: 0
140+
});
141+
142+
expect(stack).to(haveResource("AWS::AutoScaling::AutoScalingGroup", {
143+
MinSize: "0",
144+
MaxSize: "0",
145+
DesiredCapacity: "0",
146+
}
147+
));
148+
149+
test.done();
150+
},
151+
129152
'addToRolePolicy can be used to add statements to the role policy'(test: Test) {
130153
const stack = new cdk.Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }});
131154
const vpc = mockVpc(stack);

0 commit comments

Comments
 (0)