Skip to content

Commit 40a6ceb

Browse files
feat(rds): allow DatabaseClusterFromSnapshot to set copyTagsToSnapshot property (#19932)
This change will now allow users to set `copyTagsToSnapshot` attribute for the `DatabaseClusterFromSnapshot`. This will now be consistent with the way the database instance works. _Integration test may not be possible since this requires a valid snapshot to pre-exist before building the CDK stack to generate the CDK local snapshot._ _It might be possible to add a snapshot first by creating a new DB Cluster taking a manual snapshot then using that in `DatabaseClusterFromSnapshot` but it will become a hassle for anyone else in future to maintain or update since they will always need to proceed in the same manner to get the exact snapshot._ _An integration test for `copyTagsToSnapshot` already exists for `DatabaseCluster` in `integ.cluster.js` which is passing successfully on executing the tests._ Closes #19884 ---- ### All Submissions: * [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8362efe commit 40a6ceb

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

packages/@aws-cdk/aws-rds/lib/cluster.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,19 @@ interface DatabaseClusterBaseProps {
259259
readonly storageEncrypted?: boolean
260260

261261
/**
262-
* The KMS key for storage encryption.
263-
* If specified, {@link storageEncrypted} will be set to `true`.
264-
*
265-
* @default - if storageEncrypted is true then the default master key, no key otherwise
266-
*/
262+
* The KMS key for storage encryption.
263+
* If specified, {@link storageEncrypted} will be set to `true`.
264+
*
265+
* @default - if storageEncrypted is true then the default master key, no key otherwise
266+
*/
267267
readonly storageEncryptionKey?: kms.IKey;
268+
269+
/**
270+
* Whether to copy tags to the snapshot when a snapshot is created.
271+
*
272+
* @default - true
273+
*/
274+
readonly copyTagsToSnapshot?: boolean;
268275
}
269276

270277
/**
@@ -425,6 +432,8 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
425432
// Encryption
426433
kmsKeyId: props.storageEncryptionKey?.keyArn,
427434
storageEncrypted: props.storageEncryptionKey ? true : props.storageEncrypted,
435+
// Tags
436+
copyTagsToSnapshot: props.copyTagsToSnapshot ?? true,
428437
};
429438
}
430439
}
@@ -501,13 +510,6 @@ export interface DatabaseClusterProps extends DatabaseClusterBaseProps {
501510
* @default - A username of 'admin' (or 'postgres' for PostgreSQL) and SecretsManager-generated password
502511
*/
503512
readonly credentials?: Credentials;
504-
505-
/**
506-
* Whether to copy tags to the snapshot when a snapshot is created.
507-
*
508-
* @default: true
509-
*/
510-
readonly copyTagsToSnapshot?: boolean;
511513
}
512514

513515
/**
@@ -558,8 +560,6 @@ export class DatabaseCluster extends DatabaseClusterNew {
558560
// Admin
559561
masterUsername: credentials.username,
560562
masterUserPassword: credentials.password?.unsafeUnwrap(),
561-
// Tags
562-
copyTagsToSnapshot: props.copyTagsToSnapshot ?? true,
563563
});
564564

565565
this.clusterIdentifier = cluster.ref;

packages/@aws-cdk/aws-rds/test/cluster.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,7 @@ describe('cluster', () => {
19971997
VpcSecurityGroupIds: [{ 'Fn::GetAtt': ['DatabaseSecurityGroup5C91FDCB', 'GroupId'] }],
19981998
SnapshotIdentifier: 'mySnapshot',
19991999
EnableIAMDatabaseAuthentication: true,
2000+
CopyTagsToSnapshot: true,
20002001
},
20012002
DeletionPolicy: 'Snapshot',
20022003
UpdateReplacePolicy: 'Snapshot',

0 commit comments

Comments
 (0)