From 40a6ceb9983694a3645edd78167e93825a9049e9 Mon Sep 17 00:00:00 2001 From: Anurag Mohapatra Date: Tue, 26 Apr 2022 05:17:12 +1000 Subject: [PATCH] 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* --- packages/@aws-cdk/aws-rds/lib/cluster.ts | 28 +++++++++---------- .../@aws-cdk/aws-rds/test/cluster.test.ts | 1 + 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/@aws-cdk/aws-rds/lib/cluster.ts b/packages/@aws-cdk/aws-rds/lib/cluster.ts index b31f6a8ee6ef4..d8423cfdfdd6d 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster.ts @@ -259,12 +259,19 @@ interface DatabaseClusterBaseProps { readonly storageEncrypted?: boolean /** - * The KMS key for storage encryption. - * If specified, {@link storageEncrypted} will be set to `true`. - * - * @default - if storageEncrypted is true then the default master key, no key otherwise - */ + * The KMS key for storage encryption. + * If specified, {@link storageEncrypted} will be set to `true`. + * + * @default - if storageEncrypted is true then the default master key, no key otherwise + */ readonly storageEncryptionKey?: kms.IKey; + + /** + * Whether to copy tags to the snapshot when a snapshot is created. + * + * @default - true + */ + readonly copyTagsToSnapshot?: boolean; } /** @@ -425,6 +432,8 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase { // Encryption kmsKeyId: props.storageEncryptionKey?.keyArn, storageEncrypted: props.storageEncryptionKey ? true : props.storageEncrypted, + // Tags + copyTagsToSnapshot: props.copyTagsToSnapshot ?? true, }; } } @@ -501,13 +510,6 @@ export interface DatabaseClusterProps extends DatabaseClusterBaseProps { * @default - A username of 'admin' (or 'postgres' for PostgreSQL) and SecretsManager-generated password */ readonly credentials?: Credentials; - - /** - * Whether to copy tags to the snapshot when a snapshot is created. - * - * @default: true - */ - readonly copyTagsToSnapshot?: boolean; } /** @@ -558,8 +560,6 @@ export class DatabaseCluster extends DatabaseClusterNew { // Admin masterUsername: credentials.username, masterUserPassword: credentials.password?.unsafeUnwrap(), - // Tags - copyTagsToSnapshot: props.copyTagsToSnapshot ?? true, }); this.clusterIdentifier = cluster.ref; diff --git a/packages/@aws-cdk/aws-rds/test/cluster.test.ts b/packages/@aws-cdk/aws-rds/test/cluster.test.ts index e30cd8ad74e15..dddc3edc9e97a 100644 --- a/packages/@aws-cdk/aws-rds/test/cluster.test.ts +++ b/packages/@aws-cdk/aws-rds/test/cluster.test.ts @@ -1997,6 +1997,7 @@ describe('cluster', () => { VpcSecurityGroupIds: [{ 'Fn::GetAtt': ['DatabaseSecurityGroup5C91FDCB', 'GroupId'] }], SnapshotIdentifier: 'mySnapshot', EnableIAMDatabaseAuthentication: true, + CopyTagsToSnapshot: true, }, DeletionPolicy: 'Snapshot', UpdateReplacePolicy: 'Snapshot',