RDS: `DatabaseClusterFromSnapshot` should allow setting `copyTagsToSnapshot`
See original GitHub issueDescribe the bug
Today, the copyTagsToSnapshot
property exists on DatabaseClusterProps
not DatabaseClusterBaseProps
: https://github.com/aws/aws-cdk/blob/789e8d2aaa0aefb6d17e4ebc0d56c17e9999add0/packages/%40aws-cdk/aws-rds/lib/cluster.ts#L497-L511
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
): https://github.com/aws/aws-cdk/blob/789e8d2aaa0aefb6d17e4ebc0d56c17e9999add0/packages/@aws-cdk/aws-rds/lib/cluster.ts#L505-L510
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
Issue Analytics
- State:
- Created a year ago
- Comments:7 (6 by maintainers)
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.
⚠️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.