Skip to content

Commit

Permalink
feat(rds): add engineVersion to DatabaseCluster
Browse files Browse the repository at this point in the history
Without this change, CDK's RDS DatabaseCluster is not very useful
because you can only deploy the default versions
of the given database engine.

This change adds an optional prop `engineVersion`

fixes aws#2212
  • Loading branch information
Joe Hillenbrand committed May 30, 2019
1 parent 04d37af commit da13b5b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export interface DatabaseClusterProps {
*/
readonly engine: DatabaseClusterEngine;

/**
* What version of the database to start
*
* @default - The default for the engine is used.
*/
readonly engineVersion?: string;

/**
* How many replicas/instances to create
*
Expand Down Expand Up @@ -243,6 +250,13 @@ export class DatabaseCluster extends DatabaseClusterBase {
*/
public readonly engine: DatabaseClusterEngine;

/**
* The database version of the engine of this cluster
*
* @default - The default for the engine is used.
*/
public readonly engineVersion?: string;

/**
* The VPC where the DB subnet group is created.
*/
Expand Down Expand Up @@ -287,10 +301,12 @@ export class DatabaseCluster extends DatabaseClusterBase {
}

this.engine = props.engine;
this.engineVersion = props.engineVersion;

const cluster = new CfnDBCluster(this, 'Resource', {
// Basic
engine: this.engine,
engineVersion: this.engineVersion,
dbClusterIdentifier: props.clusterIdentifier,
dbSubnetGroupName: subnetGroup.ref,
vpcSecurityGroupIds: [this.securityGroupId],
Expand Down Expand Up @@ -348,6 +364,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
const instance = new CfnDBInstance(this, `Instance${instanceIndex}`, {
// Link to cluster
engine: props.engine,
engineVersion: props.engineVersion,
dbClusterIdentifier: cluster.ref,
dbInstanceIdentifier: instanceIdentifier,
// Instance properties
Expand Down
54 changes: 54 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,60 @@ export = {
}
}));

test.done();
},

'create a cluster using a specific version of MySQL'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AuroraMysql,
engineVersion: "5.7.mysql_aurora.2.04.4",
masterUser: {
username: 'admin'
},
instanceProps: {
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small),
vpc
},
});

// THEN
expect(stack).to(haveResource('AWS::RDS::DBCluster', {
Engine: "aurora-mysql",
EngineVersion: "5.7.mysql_aurora.2.04.4",
}));

test.done();
},

'create a cluster using a specific version of Postgresql'(test: Test) {
// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AuroraPostgresql,
engineVersion: "10.7",
masterUser: {
username: 'admin'
},
instanceProps: {
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small),
vpc
},
});

// THEN
expect(stack).to(haveResource('AWS::RDS::DBCluster', {
Engine: "aurora-postgresql",
EngineVersion: "10.7",
}));

test.done();
}
};
Expand Down

0 comments on commit da13b5b

Please sign in to comment.