Skip to content

Commit

Permalink
feat(backup): add recovery point tags param to backup plan rule (aws#…
Browse files Browse the repository at this point in the history
…25863)

This PR adds a `RecoveryPointTags` property to `BackupPlanRule`.

Closes aws#25671

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
go-to-k authored Jun 8, 2023
1 parent 75d1853 commit 445543c
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"version": "32.0.0",
"files": {
"14e034eeffbdd95a18b6c1a8c7a4876e1dfbedde51220bb1a196a337a6848c16": {
"cf2d89a4eac2c90005b9a1e142f1cac80cf9cd29d1b8f98f002b9f3a1849454c": {
"source": {
"path": "cdk-backup.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "14e034eeffbdd95a18b6c1a8c7a4876e1dfbedde51220bb1a196a337a6848c16.json",
"objectKey": "cf2d89a4eac2c90005b9a1e142f1cac80cf9cd29d1b8f98f002b9f3a1849454c.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
}
}
],
"RecoveryPointTags": {
"stage": "prod"
},
"RuleName": "PlanRule3",
"TargetBackupVault": {
"Fn::GetAtt": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"32.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "32.0.0",
"testCases": {
"integ.backup": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "21.0.0",
"version": "32.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"cdk-backup.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand All @@ -23,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/14e034eeffbdd95a18b6c1a8c7a4876e1dfbedde51220bb1a196a337a6848c16.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/cf2d89a4eac2c90005b9a1e142f1cac80cf9cd29d1b8f98f002b9f3a1849454c.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -95,6 +89,12 @@
]
},
"displayName": "cdk-backup"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
"id": "App",
"path": "",
"children": {
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.1.102"
}
},
"cdk-backup": {
"id": "cdk-backup",
"path": "cdk-backup",
Expand Down Expand Up @@ -45,21 +37,21 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-dynamodb.CfnTable",
"fqn": "aws-cdk-lib.aws_dynamodb.CfnTable",
"version": "0.0.0"
}
},
"ScalingRole": {
"id": "ScalingRole",
"path": "cdk-backup/Table/ScalingRole",
"constructInfo": {
"fqn": "@aws-cdk/core.Resource",
"fqn": "aws-cdk-lib.Resource",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-dynamodb.Table",
"fqn": "aws-cdk-lib.aws_dynamodb.Table",
"version": "0.0.0"
}
},
Expand All @@ -71,7 +63,7 @@
"aws:cdk:cloudformation:props": {}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-efs.CfnFileSystem",
"fqn": "aws-cdk-lib.aws_efs.CfnFileSystem",
"version": "0.0.0"
}
},
Expand All @@ -92,13 +84,13 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.CfnBackupVault",
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.BackupVault",
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
"version": "0.0.0"
}
},
Expand All @@ -119,13 +111,13 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.CfnBackupVault",
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.BackupVault",
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -203,14 +195,17 @@
"moveToColdStorageAfterDays": 30
}
}
]
],
"recoveryPointTags": {
"stage": "prod"
}
}
]
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.CfnBackupPlan",
"fqn": "aws-cdk-lib.aws_backup.CfnBackupPlan",
"version": "0.0.0"
}
},
Expand All @@ -222,6 +217,14 @@
"id": "Role",
"path": "cdk-backup/Plan/Selection/Role",
"children": {
"ImportRole": {
"id": "ImportRole",
"path": "cdk-backup/Plan/Selection/Role/ImportRole",
"constructInfo": {
"fqn": "aws-cdk-lib.Resource",
"version": "0.0.0"
}
},
"Resource": {
"id": "Resource",
"path": "cdk-backup/Plan/Selection/Role/Resource",
Expand Down Expand Up @@ -257,13 +260,13 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.CfnRole",
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-iam.Role",
"fqn": "aws-cdk-lib.aws_iam.Role",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -346,31 +349,55 @@
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.CfnBackupSelection",
"fqn": "aws-cdk-lib.aws_backup.CfnBackupSelection",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.BackupSelection",
"fqn": "aws-cdk-lib.aws_backup.BackupSelection",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/aws-backup.BackupPlan",
"fqn": "aws-cdk-lib.aws_backup.BackupPlan",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "cdk-backup/BootstrapVersion",
"constructInfo": {
"fqn": "aws-cdk-lib.CfnParameter",
"version": "0.0.0"
}
},
"CheckBootstrapVersion": {
"id": "CheckBootstrapVersion",
"path": "cdk-backup/CheckBootstrapVersion",
"constructInfo": {
"fqn": "aws-cdk-lib.CfnRule",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/core.Stack",
"fqn": "aws-cdk-lib.Stack",
"version": "0.0.0"
}
},
"Tree": {
"id": "Tree",
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.26"
}
}
},
"constructInfo": {
"fqn": "@aws-cdk/core.App",
"fqn": "aws-cdk-lib.App",
"version": "0.0.0"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class TestStack extends Stack {
moveToColdStorageAfter: Duration.days(30),
deleteAfter: Duration.days(120),
}],
recoveryPointTags: {
stage: 'prod',
},
}));
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/aws-cdk-lib/aws-backup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ plan.addRule(new backup.BackupPlanRule({
}));
```

You can assign your own metadata to the resources that are associated with the rule when restored from backup using `recoveryPointTags`. Each tag is a key-value pair.

```ts
declare const plan: backup.BackupPlan;
plan.addRule(new backup.BackupPlanRule({
recoveryPointTags: {
key: 'value',
},
}));
```

Ready-made rules are also available:

```ts
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-backup/lib/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export class BackupPlan extends Resource implements IBackupPlan {
enableContinuousBackup: rule.props.enableContinuousBackup,
targetBackupVault: vault.backupVaultName,
copyActions: rule.props.copyActions?.map(this.planCopyActions),
recoveryPointTags: rule.props.recoveryPointTags,
});
}

Expand Down
7 changes: 7 additions & 0 deletions packages/aws-cdk-lib/aws-backup/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export interface BackupPlanRuleProps {
* @default - no copy actions
*/
readonly copyActions?: BackupPlanCopyActionProps[];

/**
* To help organize your resources, you can assign your own metadata to the resources that you create. Each tag is a key-value pair.
*
* @default - no recovery point tags.
*/
readonly recoveryPointTags?: { [key: string]: string };
}

/**
Expand Down
37 changes: 37 additions & 0 deletions packages/aws-cdk-lib/aws-backup/test/plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,43 @@ test('create a plan and add rule to copy to a different vault', () => {
});
});

test('create a plan and add rule with recoveryPointTags', () => {
// GIVEN
const tags = {
key: 'value',
};

// WHEN
new BackupPlan(stack, 'Plan', {
backupPlanRules: [
new BackupPlanRule({
recoveryPointTags: tags,
}),
],
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Backup::BackupPlan', {
BackupPlan: {
BackupPlanName: 'Plan',
BackupPlanRule: [
{
RuleName: 'PlanRule0',
TargetBackupVault: {
'Fn::GetAtt': [
'PlanVault0284B0C2',
'BackupVaultName',
],
},
RecoveryPointTags: {
key: 'value',
},
},
],
},
});
});

test('throws when deleteAfter is not greater than moveToColdStorageAfter', () => {
expect(() => new BackupPlanRule({
deleteAfter: Duration.days(5),
Expand Down

0 comments on commit 445543c

Please sign in to comment.