Skip to content

Commit

Permalink
feat(docdb): graduate to stable 🚀 (#13875)
Browse files Browse the repository at this point in the history
This PR also includes some last minute ergonomic changes.

BREAKING CHANGE: `DatabaseClusterProps.instanceProps` was hoisted and all its properties are now available one level up directly in `DatabaseClusterProps`.

  - **docdb**: `DatabaseInstanceProps.instanceClass` renamed to `DatabaseInstanceProps.instanceType`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
iliapolo authored Mar 30, 2021
1 parent 08de262 commit 169c2fc
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 189 deletions.
24 changes: 6 additions & 18 deletions packages/@aws-cdk/aws-docdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@

![cfn-resources: Stable](https://img.shields.io/badge/cfn--resources-stable-success.svg?style=for-the-badge)

> All classes with the `Cfn` prefix in this module ([CFN Resources]) are always stable and safe to use.
>
> [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib
![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)

> The APIs of higher level constructs in this module are experimental and under active development.
> They are subject to non-backward compatible changes or removal in any future version. These are
> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
> announced in the release notes. This means that while you may use them, you may need to update
> your source code when upgrading to a newer version of this package.
![cdk-constructs: Stable](https://img.shields.io/badge/cdk--constructs-stable-success.svg?style=for-the-badge)

---

Expand All @@ -32,13 +22,11 @@ const cluster = new DatabaseCluster(this, 'Database', {
masterUser: {
username: 'myuser' // NOTE: 'admin' is reserved by DocumentDB
},
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
vpc
}
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
vpc
});
```

Expand Down
51 changes: 36 additions & 15 deletions packages/@aws-cdk/aws-docdb/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DatabaseSecret } from './database-secret';
import { CfnDBCluster, CfnDBInstance, CfnDBSubnetGroup } from './docdb.generated';
import { Endpoint } from './endpoint';
import { IClusterParameterGroup } from './parameter-group';
import { BackupProps, InstanceProps, Login, RotationMultiUserOptions } from './props';
import { BackupProps, Login, RotationMultiUserOptions } from './props';

/**
* Properties for a new database cluster
Expand Down Expand Up @@ -82,9 +82,37 @@ export interface DatabaseClusterProps {
readonly instanceIdentifierBase?: string;

/**
* Settings for the individual instances that are launched
* What type of instance to start for the replicas
*/
readonly instanceProps: InstanceProps;
readonly instanceType: ec2.InstanceType;

/**
* What subnets to run the DocumentDB instances in.
*
* Must be at least 2 subnets in two different AZs.
*/
readonly vpc: ec2.IVpc;

/**
* Where to place the instances within the VPC
*
* @default private subnets
*/
readonly vpcSubnets?: ec2.SubnetSelection;

/**
* Security group.
*
* @default a new security group is created.
*/
readonly securityGroup?: ec2.ISecurityGroup;

/**
* The DB parameter group to associate with the instance.
*
* @default no parameter group
*/
readonly parameterGroup?: IClusterParameterGroup;

/**
* A weekly time range in which maintenance should preferably execute.
Expand All @@ -99,13 +127,6 @@ export interface DatabaseClusterProps {
*/
readonly preferredMaintenanceWindow?: string;

/**
* Additional parameters to pass to the database engine
*
* @default - No parameter group.
*/
readonly parameterGroup?: IClusterParameterGroup;

/**
* The removal policy to apply when the cluster and its instances are removed
* or replaced during a stack update, or when the stack is deleted. This
Expand Down Expand Up @@ -275,8 +296,8 @@ export class DatabaseCluster extends DatabaseClusterBase {
constructor(scope: Construct, id: string, props: DatabaseClusterProps) {
super(scope, id);

this.vpc = props.instanceProps.vpc;
this.vpcSubnets = props.instanceProps.vpcSubnets;
this.vpc = props.vpc;
this.vpcSubnets = props.vpcSubnets;

// Determine the subnet(s) to deploy the DocDB cluster to
const { subnetIds, internetConnectivityEstablished } = this.vpc.selectSubnets(this.vpcSubnets);
Expand All @@ -295,8 +316,8 @@ export class DatabaseCluster extends DatabaseClusterBase {

// Create the security group for the DB cluster
let securityGroup: ec2.ISecurityGroup;
if (props.instanceProps.securityGroup) {
securityGroup = props.instanceProps.securityGroup;
if (props.securityGroup) {
securityGroup = props.securityGroup;
} else {
securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {
description: 'DocumentDB security group',
Expand Down Expand Up @@ -381,7 +402,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
dbClusterIdentifier: cluster.ref,
dbInstanceIdentifier: instanceIdentifier,
// Instance properties
dbInstanceClass: databaseInstanceType(props.instanceProps.instanceType),
dbInstanceClass: databaseInstanceType(props.instanceType),
});

instance.applyRemovalPolicy(props.removalPolicy, {
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-docdb/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export interface DatabaseInstanceProps {
/**
* The name of the compute and memory capacity classes.
*/
readonly instanceClass: ec2.InstanceType;
readonly instanceType: ec2.InstanceType;

/**
* The name of the Availability Zone where the DB instance will be located.
Expand Down Expand Up @@ -202,7 +202,7 @@ export class DatabaseInstance extends DatabaseInstanceBase implements IDatabaseI

const instance = new CfnDBInstance(this, 'Resource', {
dbClusterIdentifier: props.cluster.clusterIdentifier,
dbInstanceClass: `db.${props.instanceClass}`,
dbInstanceClass: `db.${props.instanceType}`,
autoMinorVersionUpgrade: props.autoMinorVersionUpgrade ?? true,
availabilityZone: props.availabilityZone,
dbInstanceIdentifier: props.dbInstanceName,
Expand Down
40 changes: 0 additions & 40 deletions packages/@aws-cdk/aws-docdb/lib/props.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as kms from '@aws-cdk/aws-kms';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import { Duration, SecretValue } from '@aws-cdk/core';
import { IClusterParameterGroup } from './parameter-group';

/**
* Backup configuration for DocumentDB databases
Expand Down Expand Up @@ -57,44 +55,6 @@ export interface Login {
readonly kmsKey?: kms.IKey;
}

/**
* Instance properties for database instances
*/
export interface InstanceProps {
/**
* What type of instance to start for the replicas
*/
readonly instanceType: ec2.InstanceType;

/**
* What subnets to run the DocumentDB instances in.
*
* Must be at least 2 subnets in two different AZs.
*/
readonly vpc: ec2.IVpc;

/**
* Where to place the instances within the VPC
*
* @default private subnets
*/
readonly vpcSubnets?: ec2.SubnetSelection;

/**
* Security group.
*
* @default a new security group is created.
*/
readonly securityGroup?: ec2.ISecurityGroup;

/**
* The DB parameter group to associate with the instance.
*
* @default no parameter group
*/
readonly parameterGroup?: IClusterParameterGroup;
}

/**
* Options to add the multi user rotation
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-docdb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
"attribute-tag:@aws-cdk/aws-docdb.DatabaseSecret.secretName"
]
},
"stability": "experimental",
"maturity": "experimental",
"stability": "stable",
"maturity": "stable",
"awscdkio": {
"announce": false
},
Expand Down
Loading

0 comments on commit 169c2fc

Please sign in to comment.