Skip to content

Commit

Permalink
feat(rds): introduce type-safe engine versions
Browse files Browse the repository at this point in the history
Change engine versions, for boh cluster and instance engines,
from strings to strongly-typed classes with static constants representing common versions.

Fixes #6532

BREAKING CHANGE: the property 'version' has been changed from string to an engine-specific
  version class; use VersionClass.of() if you need to create a specific version of an engine from a string
* **rds**: the property engineVersion in IClusterEngine changed from a string to EngineVersion
* **rds**: the property engineVersion in IInstanceEngine changed from a string to EngineVersion
* **rds**: the property parameterGroupFamily in IClusterEngine changed from required to optional
* **rds**: the property parameterGroupFamily in IInstanceEngine changed from required to optional
  • Loading branch information
skinny85 committed Jul 16, 2020
1 parent bb95957 commit 2f04ec7
Show file tree
Hide file tree
Showing 21 changed files with 1,279 additions and 347 deletions.
11 changes: 7 additions & 4 deletions packages/@aws-cdk/aws-rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ use the static factory methods on `DatabaseClusterEngine`:
```typescript
new rds.DatabaseCluster(this, 'Database', {
engine: rds.DatabaseClusterEngine.aurora({
version: '5.6.mysql_aurora.1.17.9',
version: rds.AuroraEngineVersion.VER_1_17_9, // different version class for each engine type
},
...
})
```
See [the AWS documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-engineversion)
for a list of the supported versions for each engine type.
If there isn't a constant for the exact version you want to use,
all of the `Version` classes have a static `of` method that can be used to create an arbitrary version.
By default, the master password will be generated and stored in AWS Secrets Manager with auto-generated description.
Expand Down Expand Up @@ -87,12 +87,15 @@ use the static factory methods on `DatabaseInstanceEngine`:
```typescript
const instance = new rds.DatabaseInstance(this, 'Instance', {
engine: rds.DatabaseInstanceEngine.oracleSe1({
version: '19.0.0.0',
version: rds.OracleLegacyEngineVersion.VER_19, // different version class for each engine type
}),
...
});
```
If there isn't a constant for the exact version you want to use,
all of the `Version` classes have a static `of` method that can be used to create an arbitrary version.
To use the storage auto scaling option of RDS you can specify the maximum allocated storage.
This is the upper limit to which RDS can automatically scale the storage. More info can be found
[here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling)
Expand Down
306 changes: 263 additions & 43 deletions packages/@aws-cdk/aws-rds/lib/cluster-engine.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
const cluster = new CfnDBCluster(this, 'Resource', {
// Basic
engine: props.engine.engineType,
engineVersion: props.engine.engineVersion,
engineVersion: props.engine.engineVersion?.fullVersion,
dbClusterIdentifier: props.clusterIdentifier,
dbSubnetGroupName: subnetGroup.ref,
vpcSecurityGroupIds: securityGroups.map(sg => sg.securityGroupId),
Expand Down Expand Up @@ -497,7 +497,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
const instance = new CfnDBInstance(this, `Instance${instanceIndex}`, {
// Link to cluster
engine: props.engine.engineType,
engineVersion: props.engine.engineVersion,
engineVersion: props.engine.engineVersion?.fullVersion,
dbClusterIdentifier: cluster.ref,
dbInstanceIdentifier: instanceIdentifier,
// Instance properties
Expand Down
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/engine-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* A version of an engine -
* for either a cluster, or instance.
*/
export interface EngineVersion {
/**
* The full version string of the engine,
* for example, "5.6.mysql_aurora.1.22.1".
* It can be undefined,
* which means RDS should use whatever version it deems appropriate for the given engine type.
*
* @default - no version specified
*/
readonly fullVersion?: string;

/**
* The major version of the engine,
* for example, "5.6".
* Used in specifying the ParameterGroup family
* and OptionGroup version for this engine.
*/
readonly majorVersion: string;
}
9 changes: 7 additions & 2 deletions packages/@aws-cdk/aws-rds/lib/engine.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EngineVersion } from './engine-version';

/**
* A common interface for database engines.
* Don't implement this interface directly,
Expand All @@ -14,13 +16,16 @@ export interface IEngine {
*
* @default - use the default version for this engine type
*/
readonly engineVersion?: string;
readonly engineVersion?: EngineVersion;

/**
* The family to use for ParameterGroups using this engine.
* This is usually equal to "<engineType><engineMajorVersion>",
* but can sometimes be a variation of that.
* You can pass this property when creating new ParameterGroup.
*
* @default - the ParameterGroup family is not known
* (which means the major version of the engine is also not known)
*/
readonly parameterGroupFamily: string;
readonly parameterGroupFamily?: string;
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-rds/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './engine';
export * from './engine-version';
export * from './cluster';
export * from './cluster-ref';
export * from './cluster-engine';
Expand Down
Loading

0 comments on commit 2f04ec7

Please sign in to comment.