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

fix(rds): cannot delete a stack with DbCluster set to 'Retain' #8110

Merged
merged 3 commits into from
Jun 1, 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
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ export class DatabaseCluster extends DatabaseClusterBase {
dbSubnetGroupDescription: `Subnets for ${id} database`,
subnetIds,
});
if (props.removalPolicy === RemovalPolicy.RETAIN) {
subnetGroup.applyRemovalPolicy(RemovalPolicy.RETAIN);
}

const securityGroup = props.instanceProps.securityGroup !== undefined ?
props.instanceProps.securityGroup : new ec2.SecurityGroup(this, 'SecurityGroup', {
Expand Down
24 changes: 23 additions & 1 deletion packages/@aws-cdk/aws-rds/test/test.cluster.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ABSENT, countResources, expect, haveResource, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import { ABSENT, countResources, expect, haveResource, haveResourceLike, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import { ManagedPolicy, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
Expand Down Expand Up @@ -148,6 +148,28 @@ export = {
test.done();
},

"sets the retention policy of the SubnetGroup to 'Retain' if the Cluster is created with 'Retain'"(test: Test) {
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc');

new DatabaseCluster(stack, 'Cluster', {
masterUser: { username: 'admin' },
engine: DatabaseClusterEngine.AURORA,
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.LARGE),
vpc,
},
removalPolicy: cdk.RemovalPolicy.RETAIN,
});

expect(stack).to(haveResourceLike('AWS::RDS::DBSubnetGroup', {
DeletionPolicy: 'Retain',
UpdateReplacePolicy: 'Retain',
}, ResourcePart.CompleteDefinition));

test.done();
},

'creates a secret when master credentials are not specified'(test: Test) {
// GIVEN
const stack = testStack();
Expand Down