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

RDS: DatabaseClusterFromSnapshot should allow setting copyTagsToSnapshot #19884

Closed
blimmer opened this issue Apr 12, 2022 · 7 comments · Fixed by #19932
Closed

RDS: DatabaseClusterFromSnapshot should allow setting copyTagsToSnapshot #19884

blimmer opened this issue Apr 12, 2022 · 7 comments · Fixed by #19932
Assignees
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database effort/small Small work item – less than a day of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs feature-request A feature should be added or improved. p2

Comments

@blimmer
Copy link
Contributor

blimmer commented Apr 12, 2022

Describe the bug

Today, the copyTagsToSnapshot property exists on DatabaseClusterProps not DatabaseClusterBaseProps:

export interface DatabaseClusterProps extends DatabaseClusterBaseProps {
/**
* Credentials for the administrative user
*
* @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;
}

It's also not set in the DatabaseClusterFromSnapshot construct, so if you switch a DatabaseCluster to DatabaseClusterFromSnapshot, you'll get this diff:

[~] AWS::RDS::DBCluster CdkPipelinesPrototype-dev-us-east-1/Database/Database/cdk-pipeline-example-dev-Cluster DatabasecdkpipelineexampledevClusterC6927963 replace
 ├─ [-] CopyTagsToSnapshot
 │   └─ true
<trimmed>

This is especially noticeable because the value defaults to true in the L2 construct, which is different from the CloudFormation default (false):

/**
* Whether to copy tags to the snapshot when a snapshot is created.
*
* @default: true
*/
readonly copyTagsToSnapshot?: boolean;

Unlike other values that are explicitly unset when using DatabaseClusterFromSnapshot (e.g., KmsKeyId, MasterUsername, MasterUserPassword - see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html#cfn-rds-dbcluster-kmskeyid), the docs for CopyTagsToSnapshot don't specify that you shouldn't set the value when restoring from a snapshot.

Expected Behavior

I expected to be able to switch from a DatabaseCluster to a DatabaseClusterFromSnapshot while retaining the same default behaviors.

Current Behavior

Currently, the CopyTagsToSnapshot value shows as being unset (which will change to the CloudFormation default of false) when changing from a DatabaseCluster to DatabaseClusterFromSnapshot.

Reproduction Steps

https://github.com/blimmer/cdk-bug-reports/compare/rds-copy-tags-to-snapshot?expand=1

In this simple stack:

import { Stack, StackProps } from 'aws-cdk-lib';
import { Vpc } from 'aws-cdk-lib/aws-ec2';
import { AuroraPostgresEngineVersion, DatabaseCluster, DatabaseClusterEngine, DatabaseClusterFromSnapshot } from 'aws-cdk-lib/aws-rds';
import { Construct } from 'constructs';

export class CdkBugReportsStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const vpc = new Vpc(this, 'VPC')
    new DatabaseCluster(this, 'DatabaseCluster', {
      engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_13_4 }),
      instanceProps: {
        vpc
      }
    })

    new DatabaseClusterFromSnapshot(this, 'DatabaseClusterFromSnapshot', {
      snapshotIdentifier: 'arn:aws:rds:us-east-1:12345678910:cluster-snapshot:rds:example-2022-04-12-09-26',
      engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_13_4 }),
      instanceProps: {
        vpc
      }
    })
  }
}

The resource with the id DatabaseCluster has CopyTagsToSnapshot set to true (the default in the L2 construct):

"DatabaseCluster68FC2945": {
  "Type": "AWS::RDS::DBCluster",
  "Properties": {
    "Engine": "aurora-postgresql",
    "CopyTagsToSnapshot": true,

However, the one restored from the snapshot does not have this value set:

"DatabaseClusterFromSnapshotB2BFF6A0": {
  "Type": "AWS::RDS::DBCluster",
  "Properties": {
    "Engine": "aurora-postgresql",
	// CopyTagsToSnapshot is missing

Possible Solution

I think copyTagsToSnapshot should be moved up to DatabaseClusterBaseProps and should default to true for DatabaseClusterFromSnapshot for consistency.

Additional Information/Context

You can work around this temporarily by setting the value on the L1 construct, e.g.:

const db = new DatabaseClusterFromSnapshot(this, 'DatabaseClusterFromSnapshot', {
  snapshotIdentifier: 'arn:aws:rds:us-east-1:12345678910:cluster-snapshot:rds:example-2022-04-12-09-26',
  engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_13_4 }),
  instanceProps: {
    vpc
  }
});
(db.node.defaultChild as CfnDBCluster).copyTagsToSnapshot = true;

CDK CLI Version

2.20.0

Framework Version

No response

Node.js Version

16.14.0

OS

macOS

Language

Typescript

Language Version

No response

Other information

No response

@blimmer blimmer added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2022
@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Apr 12, 2022
@skinny85
Copy link
Contributor

Thanks for opening the issue @blimmer!

But I wonder: does this setting make sense on DatabaseClusterFromSnapshot? Can this Database also create a snapshot?

Thanks,
Adam

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 12, 2022
@blimmer
Copy link
Contributor Author

blimmer commented Apr 12, 2022

@skinny85 I believe so, yes! The new DatabaseClusterFromSnapshot is just a regular ol' DatabaseCluster and will produce snapshots according to the backup configuration. You can also take manual snapshots of the restored cluster, as well.

@skinny85
Copy link
Contributor

OK, so I guess this is just a matter of moving copyTagsToSnapshot from DatabaseClusterProps to DatabaseClusterBaseProps, and then the logic of using it from DatabaseCluster here to DatabaseClusterNew (somewhere here most likely)?

@skinny85 skinny85 added p2 feature-request A feature should be added or improved. effort/small Small work item – less than a day of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs and removed bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2022
@skinny85 skinny85 changed the title (aws-rds): DatabaseClusterFromSnapshot should set copyTagsToSnapshot RDS: DatabaseClusterFromSnapshot should allow setting copyTagsToSnapshot Apr 12, 2022
@blimmer
Copy link
Contributor Author

blimmer commented Apr 12, 2022

Yep, that sounds like how I would think about solving it, too.

@skinny85
Copy link
Contributor

We encourage community contributions, so if you'd like to open us a Pull Request adding this feature, that would be fantastic! 😉 Our "Contributing" guide: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md.

@AnuragMohapatra
Copy link
Contributor

Hi,

I would like to pick this change and help in implementing it, will open a PR with the solution soon.

Let me know in case of any concerns.

@mergify mergify bot closed this as completed in #19932 Apr 25, 2022
mergify bot pushed a commit that referenced this issue Apr 25, 2022
…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*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database effort/small Small work item – less than a day of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants