Skip to content

Commit

Permalink
fix(aws-rds): unable to create cluster with a single instance (#578)
Browse files Browse the repository at this point in the history
The docs state that you should be able to create a cluster with a single instance however there is a trivial error that prevents this.
  • Loading branch information
cookejames authored and Elad Ben-Israel committed Aug 16, 2018
1 parent 0b92202 commit 0220bbc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class DatabaseCluster extends DatabaseClusterRef {
this.readerEndpoint = new Endpoint(cluster.dbClusterReadEndpointAddress, cluster.dbClusterEndpointPort);

const instanceCount = props.instances != null ? props.instances : 2;
if (instanceCount <= 1) {
if (instanceCount < 1) {
throw new Error('At least one instance is required');
}

Expand Down
32 changes: 31 additions & 1 deletion packages/@aws-cdk/aws-rds/test/test.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,37 @@ export = {
// THEN: No error

test.done();
}
},
'can create a cluster with a single instance'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = new ec2.VpcNetwork(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.Aurora,
instances: 1,
masterUser: {
username: new Username('admin'),
password: new Password('tooshort'),
},
instanceProps: {
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small),
vpc
}
});

// THEN
expect(stack).to(haveResource('AWS::RDS::DBCluster', {
Engine: "aurora",
DBSubnetGroupName: { Ref: "DatabaseSubnets56F17B9A" },
MasterUsername: "admin",
MasterUserPassword: "tooshort",
VpcSecurityGroupIds: [ {"Fn::GetAtt": ["DatabaseSecurityGroup5C91FDCB", "GroupId"]}]
}));

test.done();
},
};

function testStack() {
Expand Down

0 comments on commit 0220bbc

Please sign in to comment.