Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rds): introduce type-safe engine versions #9016

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 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
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
},
...
})
```

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 @@ -86,13 +86,16 @@ use the static factory methods on `DatabaseInstanceEngine`:

```typescript
const instance = new rds.DatabaseInstance(this, 'Instance', {
engine: rds.DatabaseInstanceEngine.oracleSe1({
version: '19.0.0.0',
engine: rds.DatabaseInstanceEngine.oracleSe2({
version: rds.OracleEngineVersion.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 Expand Up @@ -173,24 +176,27 @@ instance.addRotationSingleUser(); // Will rotate automatically after 30 days
[example of setting up master password rotation for a cluster](test/integ.cluster-rotation.lit.ts)

The multi user rotation scheme is also available:

```ts
instance.addRotationMultiUser('MyUser', {
secret: myImportedSecret // This secret must have the `masterarn` key
secret: myImportedSecret, // This secret must have the `masterarn` key
});
```

It's also possible to create user credentials together with the instance/cluster and add rotation:

```ts
const myUserSecret = new rds.DatabaseSecret(this, 'MyUserSecret', {
username: 'myuser'
masterSecret: instance.secret
username: 'myuser',
masterSecret: instance.secret,
});
const myUserSecretAttached = myUserSecret.attach(instance); // Adds DB connections information in the secret

instance.addRotationMultiUser('MyUser', { // Add rotation using the multi user scheme
secret: myUserSecretAttached
secret: myUserSecretAttached,
});
```

**Note**: This user must be created manually in the database using the master credentials.
The rotation will start as soon as this user exists.

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.
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
*
* @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