Skip to content

Commit

Permalink
fix(aws-rds): exception message in providing deploy-time only value f…
Browse files Browse the repository at this point in the history
…or instanceCount

fixes #13558
  • Loading branch information
BLasan committed Mar 25, 2021
1 parent 7966f8d commit 642a5eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ interface InstanceConfig {
*/
function createInstances(cluster: DatabaseClusterNew, props: DatabaseClusterBaseProps, subnetGroup: ISubnetGroup): InstanceConfig {
const instanceCount = props.instances != null ? props.instances : 2;
if (Token.isUnresolved(instanceCount)) {
throw new Error('The number of instances an RDS Cluster consists of cannot be provided as a deploy-time only value!');
}
if (instanceCount < 1) {
throw new Error('At least one instance is required');
}
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ describe('cluster', () => {

});

test('check instanceCount is a token', () => {
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');
expect(() => {
createRDSCluster(stack, vpc);
}).toThrow('The number of instances an RDS Cluster consists of cannot be provided as a deploy-time only value!')

});

test('can create a cluster with a single instance', () => {
// GIVEN
const stack = testStack();
Expand Down Expand Up @@ -1959,3 +1968,14 @@ function testStack(app?: cdk.App) {
stack.node.setContext('availability-zones:12345:us-test-1', ['us-test-1a', 'us-test-1b']);
return stack;
}

function createRDSCluster(stack: any, vpc: any) {
new DatabaseCluster(stack, 'Database', {
instances: cdk.Token.asNumber("1"),
engine: DatabaseClusterEngine.AURORA,
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
vpc,
},
});
}

0 comments on commit 642a5eb

Please sign in to comment.