-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rds): support existing cluster subnet groups (#10391)
Enable users with existing cluster subnet groups to specify an existing group, rather than creating a new group. _Note: Marked as exempt-readme because I don't think this deserves its own README section. Feel free to disagree._ fixes #9991 BREAKING CHANGE: removed protected member `subnetGroup` from DatabaseCluster classes ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
8 changed files
with
300 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||
import { Construct, IResource, RemovalPolicy, Resource } from '@aws-cdk/core'; | ||
import { CfnDBSubnetGroup } from './rds.generated'; | ||
|
||
/** | ||
* Interface for a subnet group. | ||
*/ | ||
export interface ISubnetGroup extends IResource { | ||
/** | ||
* The name of the subnet group. | ||
* @attribute | ||
*/ | ||
readonly subnetGroupName: string; | ||
} | ||
|
||
/** | ||
* Properties for creating a SubnetGroup. | ||
*/ | ||
export interface SubnetGroupProps { | ||
/** | ||
* Description of the subnet group. | ||
*/ | ||
readonly description: string; | ||
|
||
/** | ||
* The VPC to place the subnet group in. | ||
*/ | ||
readonly vpc: ec2.IVpc; | ||
|
||
/** | ||
* The name of the subnet group. | ||
* | ||
* @default - a name is generated | ||
*/ | ||
readonly subnetGroupName?: string; | ||
|
||
/** | ||
* Which subnets within the VPC to associate with this group. | ||
* | ||
* @default - private subnets | ||
*/ | ||
readonly vpcSubnets?: ec2.SubnetSelection; | ||
|
||
/** | ||
* The removal policy to apply when the subnet group are removed | ||
* from the stack or replaced during an update. | ||
* | ||
* @default RemovalPolicy.DESTROY | ||
*/ | ||
readonly removalPolicy?: RemovalPolicy | ||
} | ||
|
||
/** | ||
* Class for creating a RDS DB subnet group | ||
* | ||
* @resource AWS::RDS::DBSubnetGroup | ||
*/ | ||
export class SubnetGroup extends Resource implements ISubnetGroup { | ||
|
||
/** | ||
* Imports an existing subnet group by name. | ||
*/ | ||
public static fromSubnetGroupName(scope: Construct, id: string, subnetGroupName: string): ISubnetGroup { | ||
return new class extends Resource implements ISubnetGroup { | ||
public readonly subnetGroupName = subnetGroupName; | ||
}(scope, id); | ||
} | ||
|
||
public readonly subnetGroupName: string; | ||
|
||
constructor(scope: Construct, id: string, props: SubnetGroupProps) { | ||
super(scope, id); | ||
|
||
const { subnetIds } = props.vpc.selectSubnets(props.vpcSubnets ?? { subnetType: ec2.SubnetType.PRIVATE }); | ||
|
||
// Using 'Default' as the resource id for historical reasons (usage from `Instance` and `Cluster`). | ||
const subnetGroup = new CfnDBSubnetGroup(this, 'Default', { | ||
dbSubnetGroupDescription: props.description, | ||
dbSubnetGroupName: props.subnetGroupName, | ||
subnetIds, | ||
}); | ||
|
||
if (props.removalPolicy) { | ||
subnetGroup.applyRemovalPolicy(props.removalPolicy); | ||
} | ||
|
||
this.subnetGroupName = subnetGroup.ref; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.