Skip to content

Commit

Permalink
Also change maxSize and desiredCapacity
Browse files Browse the repository at this point in the history
  • Loading branch information
SoManyHs committed Oct 26, 2018
1 parent 140cdc9 commit c738832
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 103 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export class AutoScalingGroup extends cdk.Construct implements cdk.ITaggable, el
launchConfig.addDependency(this.role);

const minSize = props.minSize !== undefined ? props.minSize : 1;
const maxSize = props.maxSize || 1;
const desiredCapacity = props.desiredCapacity || 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
119 changes: 18 additions & 101 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,121 +126,38 @@ export = {
test.done();
},

'can scale min size to 0'(test: Test) {
'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(),
minSize: 0,
maxSize: 0,
desiredCapacity: 0,
vpc
});

expect(stack).toMatch({
"Resources": {
"MyFleetInstanceSecurityGroup774E8234": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "MyFleet/InstanceSecurityGroup",
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"Description": "Allow all outbound traffic by default",
"IpProtocol": "-1",
}
],
"SecurityGroupIngress": [],
"Tags": [
{
"Key": "Name",
"Value": "MyFleet"
}
],

"VpcId": "my-vpc"
}
},
"MyFleetInstanceRole25A84AB8": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
}
}
],
"Version": "2012-10-17"
}
}
},
"MyFleetInstanceProfile70A58496": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Roles": [
{
"Ref": "MyFleetInstanceRole25A84AB8"
}
]
}
expect(stack).to(haveResource("AWS::AutoScaling::AutoScalingGroup", {
MinSize: "0",
MaxSize: "0",
DesiredCapacity: "0",
LaunchConfigurationName: {
Ref: "MyFleetLaunchConfig5D7F9801"
},
"MyFleetLaunchConfig5D7F9801": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"IamInstanceProfile": {
"Ref": "MyFleetInstanceProfile70A58496"
},
"ImageId": "dummy",
"InstanceType": "m4.micro",
"SecurityGroups": [
Tags: [
{
"Fn::GetAtt": [
"MyFleetInstanceSecurityGroup774E8234",
"GroupId"
]
Key: "Name",
PropagateAtLaunch: true,
Value: "MyFleet"
}
],
"UserData": {
"Fn::Base64": "#!/bin/bash\n"
}
},
"DependsOn": [
"MyFleetInstanceRole25A84AB8"
]
},
"MyFleetASG88E55886": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"UpdatePolicy": {
"AutoScalingScheduledAction": {
"IgnoreUnmodifiedGroupSizeProperties": true
}
},
"Properties": {
"DesiredCapacity": "1",
"LaunchConfigurationName": {
"Ref": "MyFleetLaunchConfig5D7F9801"
},
"Tags": [
{
"Key": "Name",
"PropagateAtLaunch": true,
"Value": "MyFleet"
}
],

"MaxSize": "1",
"MinSize": "0",
"VPCZoneIdentifier": [
"pri1"
]
}
}
],
VPCZoneIdentifier: [
"pri1"
],
}
});
));

test.done();
},
Expand Down

0 comments on commit c738832

Please sign in to comment.