Skip to content

Commit 445543c

Browse files
authored
feat(backup): add recovery point tags param to backup plan rule (#25863)
This PR adds a `RecoveryPointTags` property to `BackupPlanRule`. Closes #25671 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 75d1853 commit 445543c

File tree

11 files changed

+127
-38
lines changed

11 files changed

+127
-38
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/cdk-backup.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "21.0.0",
2+
"version": "32.0.0",
33
"files": {
4-
"14e034eeffbdd95a18b6c1a8c7a4876e1dfbedde51220bb1a196a337a6848c16": {
4+
"cf2d89a4eac2c90005b9a1e142f1cac80cf9cd29d1b8f98f002b9f3a1849454c": {
55
"source": {
66
"path": "cdk-backup.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "14e034eeffbdd95a18b6c1a8c7a4876e1dfbedde51220bb1a196a337a6848c16.json",
12+
"objectKey": "cf2d89a4eac2c90005b9a1e142f1cac80cf9cd29d1b8f98f002b9f3a1849454c.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/cdk-backup.template.json

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
}
112112
}
113113
],
114+
"RecoveryPointTags": {
115+
"stage": "prod"
116+
},
114117
"RuleName": "PlanRule3",
115118
"TargetBackupVault": {
116119
"Fn::GetAtt": [
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"21.0.0"}
1+
{"version":"32.0.0"}

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "21.0.0",
2+
"version": "32.0.0",
33
"testCases": {
44
"integ.backup": {
55
"stacks": [

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/manifest.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
2-
"version": "21.0.0",
2+
"version": "32.0.0",
33
"artifacts": {
4-
"Tree": {
5-
"type": "cdk:tree",
6-
"properties": {
7-
"file": "tree.json"
8-
}
9-
},
104
"cdk-backup.assets": {
115
"type": "cdk:asset-manifest",
126
"properties": {
@@ -23,7 +17,7 @@
2317
"validateOnSynth": false,
2418
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2519
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/14e034eeffbdd95a18b6c1a8c7a4876e1dfbedde51220bb1a196a337a6848c16.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/cf2d89a4eac2c90005b9a1e142f1cac80cf9cd29d1b8f98f002b9f3a1849454c.json",
2721
"requiresBootstrapStackVersion": 6,
2822
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2923
"additionalDependencies": [
@@ -95,6 +89,12 @@
9589
]
9690
},
9791
"displayName": "cdk-backup"
92+
},
93+
"Tree": {
94+
"type": "cdk:tree",
95+
"properties": {
96+
"file": "tree.json"
97+
}
9898
}
9999
}
100100
}

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.js.snapshot/tree.json

+52-25
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
"id": "App",
55
"path": "",
66
"children": {
7-
"Tree": {
8-
"id": "Tree",
9-
"path": "Tree",
10-
"constructInfo": {
11-
"fqn": "constructs.Construct",
12-
"version": "10.1.102"
13-
}
14-
},
157
"cdk-backup": {
168
"id": "cdk-backup",
179
"path": "cdk-backup",
@@ -45,21 +37,21 @@
4537
}
4638
},
4739
"constructInfo": {
48-
"fqn": "@aws-cdk/aws-dynamodb.CfnTable",
40+
"fqn": "aws-cdk-lib.aws_dynamodb.CfnTable",
4941
"version": "0.0.0"
5042
}
5143
},
5244
"ScalingRole": {
5345
"id": "ScalingRole",
5446
"path": "cdk-backup/Table/ScalingRole",
5547
"constructInfo": {
56-
"fqn": "@aws-cdk/core.Resource",
48+
"fqn": "aws-cdk-lib.Resource",
5749
"version": "0.0.0"
5850
}
5951
}
6052
},
6153
"constructInfo": {
62-
"fqn": "@aws-cdk/aws-dynamodb.Table",
54+
"fqn": "aws-cdk-lib.aws_dynamodb.Table",
6355
"version": "0.0.0"
6456
}
6557
},
@@ -71,7 +63,7 @@
7163
"aws:cdk:cloudformation:props": {}
7264
},
7365
"constructInfo": {
74-
"fqn": "@aws-cdk/aws-efs.CfnFileSystem",
66+
"fqn": "aws-cdk-lib.aws_efs.CfnFileSystem",
7567
"version": "0.0.0"
7668
}
7769
},
@@ -92,13 +84,13 @@
9284
}
9385
},
9486
"constructInfo": {
95-
"fqn": "@aws-cdk/aws-backup.CfnBackupVault",
87+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
9688
"version": "0.0.0"
9789
}
9890
}
9991
},
10092
"constructInfo": {
101-
"fqn": "@aws-cdk/aws-backup.BackupVault",
93+
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
10294
"version": "0.0.0"
10395
}
10496
},
@@ -119,13 +111,13 @@
119111
}
120112
},
121113
"constructInfo": {
122-
"fqn": "@aws-cdk/aws-backup.CfnBackupVault",
114+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupVault",
123115
"version": "0.0.0"
124116
}
125117
}
126118
},
127119
"constructInfo": {
128-
"fqn": "@aws-cdk/aws-backup.BackupVault",
120+
"fqn": "aws-cdk-lib.aws_backup.BackupVault",
129121
"version": "0.0.0"
130122
}
131123
},
@@ -203,14 +195,17 @@
203195
"moveToColdStorageAfterDays": 30
204196
}
205197
}
206-
]
198+
],
199+
"recoveryPointTags": {
200+
"stage": "prod"
201+
}
207202
}
208203
]
209204
}
210205
}
211206
},
212207
"constructInfo": {
213-
"fqn": "@aws-cdk/aws-backup.CfnBackupPlan",
208+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupPlan",
214209
"version": "0.0.0"
215210
}
216211
},
@@ -222,6 +217,14 @@
222217
"id": "Role",
223218
"path": "cdk-backup/Plan/Selection/Role",
224219
"children": {
220+
"ImportRole": {
221+
"id": "ImportRole",
222+
"path": "cdk-backup/Plan/Selection/Role/ImportRole",
223+
"constructInfo": {
224+
"fqn": "aws-cdk-lib.Resource",
225+
"version": "0.0.0"
226+
}
227+
},
225228
"Resource": {
226229
"id": "Resource",
227230
"path": "cdk-backup/Plan/Selection/Role/Resource",
@@ -257,13 +260,13 @@
257260
}
258261
},
259262
"constructInfo": {
260-
"fqn": "@aws-cdk/aws-iam.CfnRole",
263+
"fqn": "aws-cdk-lib.aws_iam.CfnRole",
261264
"version": "0.0.0"
262265
}
263266
}
264267
},
265268
"constructInfo": {
266-
"fqn": "@aws-cdk/aws-iam.Role",
269+
"fqn": "aws-cdk-lib.aws_iam.Role",
267270
"version": "0.0.0"
268271
}
269272
},
@@ -346,31 +349,55 @@
346349
}
347350
},
348351
"constructInfo": {
349-
"fqn": "@aws-cdk/aws-backup.CfnBackupSelection",
352+
"fqn": "aws-cdk-lib.aws_backup.CfnBackupSelection",
350353
"version": "0.0.0"
351354
}
352355
}
353356
},
354357
"constructInfo": {
355-
"fqn": "@aws-cdk/aws-backup.BackupSelection",
358+
"fqn": "aws-cdk-lib.aws_backup.BackupSelection",
356359
"version": "0.0.0"
357360
}
358361
}
359362
},
360363
"constructInfo": {
361-
"fqn": "@aws-cdk/aws-backup.BackupPlan",
364+
"fqn": "aws-cdk-lib.aws_backup.BackupPlan",
365+
"version": "0.0.0"
366+
}
367+
},
368+
"BootstrapVersion": {
369+
"id": "BootstrapVersion",
370+
"path": "cdk-backup/BootstrapVersion",
371+
"constructInfo": {
372+
"fqn": "aws-cdk-lib.CfnParameter",
373+
"version": "0.0.0"
374+
}
375+
},
376+
"CheckBootstrapVersion": {
377+
"id": "CheckBootstrapVersion",
378+
"path": "cdk-backup/CheckBootstrapVersion",
379+
"constructInfo": {
380+
"fqn": "aws-cdk-lib.CfnRule",
362381
"version": "0.0.0"
363382
}
364383
}
365384
},
366385
"constructInfo": {
367-
"fqn": "@aws-cdk/core.Stack",
386+
"fqn": "aws-cdk-lib.Stack",
368387
"version": "0.0.0"
369388
}
389+
},
390+
"Tree": {
391+
"id": "Tree",
392+
"path": "Tree",
393+
"constructInfo": {
394+
"fqn": "constructs.Construct",
395+
"version": "10.2.26"
396+
}
370397
}
371398
},
372399
"constructInfo": {
373-
"fqn": "@aws-cdk/core.App",
400+
"fqn": "aws-cdk-lib.App",
374401
"version": "0.0.0"
375402
}
376403
}

packages/@aws-cdk-testing/framework-integ/test/aws-backup/test/integ.backup.ts

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class TestStack extends Stack {
4646
moveToColdStorageAfter: Duration.days(30),
4747
deleteAfter: Duration.days(120),
4848
}],
49+
recoveryPointTags: {
50+
stage: 'prod',
51+
},
4952
}));
5053
}
5154
}

packages/aws-cdk-lib/aws-backup/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ plan.addRule(new backup.BackupPlanRule({
104104
}));
105105
```
106106

107+
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.
108+
109+
```ts
110+
declare const plan: backup.BackupPlan;
111+
plan.addRule(new backup.BackupPlanRule({
112+
recoveryPointTags: {
113+
key: 'value',
114+
},
115+
}));
116+
```
117+
107118
Ready-made rules are also available:
108119

109120
```ts

packages/aws-cdk-lib/aws-backup/lib/plan.ts

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export class BackupPlan extends Resource implements IBackupPlan {
192192
enableContinuousBackup: rule.props.enableContinuousBackup,
193193
targetBackupVault: vault.backupVaultName,
194194
copyActions: rule.props.copyActions?.map(this.planCopyActions),
195+
recoveryPointTags: rule.props.recoveryPointTags,
195196
});
196197
}
197198

packages/aws-cdk-lib/aws-backup/lib/rule.ts

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ export interface BackupPlanRuleProps {
7777
* @default - no copy actions
7878
*/
7979
readonly copyActions?: BackupPlanCopyActionProps[];
80+
81+
/**
82+
* To help organize your resources, you can assign your own metadata to the resources that you create. Each tag is a key-value pair.
83+
*
84+
* @default - no recovery point tags.
85+
*/
86+
readonly recoveryPointTags?: { [key: string]: string };
8087
}
8188

8289
/**

packages/aws-cdk-lib/aws-backup/test/plan.test.ts

+37
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,43 @@ test('create a plan and add rule to copy to a different vault', () => {
336336
});
337337
});
338338

339+
test('create a plan and add rule with recoveryPointTags', () => {
340+
// GIVEN
341+
const tags = {
342+
key: 'value',
343+
};
344+
345+
// WHEN
346+
new BackupPlan(stack, 'Plan', {
347+
backupPlanRules: [
348+
new BackupPlanRule({
349+
recoveryPointTags: tags,
350+
}),
351+
],
352+
});
353+
354+
// THEN
355+
Template.fromStack(stack).hasResourceProperties('AWS::Backup::BackupPlan', {
356+
BackupPlan: {
357+
BackupPlanName: 'Plan',
358+
BackupPlanRule: [
359+
{
360+
RuleName: 'PlanRule0',
361+
TargetBackupVault: {
362+
'Fn::GetAtt': [
363+
'PlanVault0284B0C2',
364+
'BackupVaultName',
365+
],
366+
},
367+
RecoveryPointTags: {
368+
key: 'value',
369+
},
370+
},
371+
],
372+
},
373+
});
374+
});
375+
339376
test('throws when deleteAfter is not greater than moveToColdStorageAfter', () => {
340377
expect(() => new BackupPlanRule({
341378
deleteAfter: Duration.days(5),

0 commit comments

Comments
 (0)