From a047963b6009c015e43fdb6e620a28487882ca7b Mon Sep 17 00:00:00 2001 From: Joe Hillenbrand Date: Thu, 30 May 2019 16:22:55 -0700 Subject: [PATCH 1/2] feat(rds): add engineVersion to DatabaseCluster 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 #2212 --- packages/@aws-cdk/aws-rds/lib/cluster.ts | 17 ++++++ .../@aws-cdk/aws-rds/test/test.cluster.ts | 54 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/packages/@aws-cdk/aws-rds/lib/cluster.ts b/packages/@aws-cdk/aws-rds/lib/cluster.ts index 95f634e6a0fe0..ff9fc6275b1fc 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster.ts @@ -19,6 +19,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 * @@ -239,6 +246,13 @@ export class DatabaseCluster extends DatabaseClusterBase { */ public readonly secret?: secretsmanager.ISecret; + /** + * The database version of the engine of this cluster + * + * @default - The default for the engine is used. + */ + public readonly engineVersion?: string; + /** * The database engine of this cluster */ @@ -288,10 +302,12 @@ export class DatabaseCluster extends DatabaseClusterBase { } this.secretRotationApplication = props.engine.secretRotationApplication; + this.engineVersion = props.engineVersion; const cluster = new CfnDBCluster(this, 'Resource', { // Basic engine: props.engine.name, + engineVersion: this.engineVersion, dbClusterIdentifier: props.clusterIdentifier, dbSubnetGroupName: subnetGroup.ref, vpcSecurityGroupIds: [this.securityGroupId], @@ -349,6 +365,7 @@ export class DatabaseCluster extends DatabaseClusterBase { const instance = new CfnDBInstance(this, `Instance${instanceIndex}`, { // Link to cluster engine: props.engine.name, + engineVersion: props.engineVersion, dbClusterIdentifier: cluster.ref, dbInstanceIdentifier: instanceIdentifier, // Instance properties diff --git a/packages/@aws-cdk/aws-rds/test/test.cluster.ts b/packages/@aws-cdk/aws-rds/test/test.cluster.ts index 2924020ae6198..a56b720228e54 100644 --- a/packages/@aws-cdk/aws-rds/test/test.cluster.ts +++ b/packages/@aws-cdk/aws-rds/test/test.cluster.ts @@ -266,6 +266,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(); + } }; function testStack() { From c5c45c56d1b3f14073fd8cf716d7b3fc26c43988 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Fri, 31 May 2019 14:34:25 +0200 Subject: [PATCH 2/2] Remove engineVersion attribute --- packages/@aws-cdk/aws-rds/lib/cluster.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/@aws-cdk/aws-rds/lib/cluster.ts b/packages/@aws-cdk/aws-rds/lib/cluster.ts index ff9fc6275b1fc..bc3cb557dd5b6 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster.ts @@ -246,13 +246,6 @@ export class DatabaseCluster extends DatabaseClusterBase { */ public readonly secret?: secretsmanager.ISecret; - /** - * The database version of the engine of this cluster - * - * @default - The default for the engine is used. - */ - public readonly engineVersion?: string; - /** * The database engine of this cluster */ @@ -302,12 +295,11 @@ export class DatabaseCluster extends DatabaseClusterBase { } this.secretRotationApplication = props.engine.secretRotationApplication; - this.engineVersion = props.engineVersion; const cluster = new CfnDBCluster(this, 'Resource', { // Basic engine: props.engine.name, - engineVersion: this.engineVersion, + engineVersion: props.engineVersion, dbClusterIdentifier: props.clusterIdentifier, dbSubnetGroupName: subnetGroup.ref, vpcSecurityGroupIds: [this.securityGroupId],