Skip to content

Commit

Permalink
feat(rds): allow DatabaseClusterFromSnapshot to set `copyTagsToSnap…
Browse files Browse the repository at this point in the history
…shot` 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*
  • Loading branch information
AnuragMohapatra committed Apr 25, 2022
1 parent 8362efe commit 40a6ceb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/@aws-cdk/aws-rds/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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,
};
}
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,7 @@ describe('cluster', () => {
VpcSecurityGroupIds: [{ 'Fn::GetAtt': ['DatabaseSecurityGroup5C91FDCB', 'GroupId'] }],
SnapshotIdentifier: 'mySnapshot',
EnableIAMDatabaseAuthentication: true,
CopyTagsToSnapshot: true,
},
DeletionPolicy: 'Snapshot',
UpdateReplacePolicy: 'Snapshot',
Expand Down

0 comments on commit 40a6ceb

Please sign in to comment.