Skip to content

fix(backup): use Conditions instead of ListOfTags in BackupSelection#37787

Open
emfrab wants to merge 6 commits intoaws:mainfrom
emfrab:fix/backup-resource-tags
Open

fix(backup): use Conditions instead of ListOfTags in BackupSelection#37787
emfrab wants to merge 6 commits intoaws:mainfrom
emfrab:fix/backup-resource-tags

Conversation

@emfrab
Copy link
Copy Markdown

@emfrab emfrab commented May 7, 2026

Issue # (if applicable)

Closes #37771
Closes #18911

Reason for this change

BackupSelection generates a ListOfTags CloudFormation property instead of Conditions. This has two consequences:

  1. Wrong logic: ListOfTags uses OR semantics — a resource matching any tag is selected. Conditions uses AND semantics — a resource must match all conditions. The AWS Console's "Tags - equal" filter uses Conditions, so tag-based selections created via CDK behave differently than equivalent console-created selections.
  2. Limited operations: ListOfTags only supports StringEquals. Conditions supports StringEquals, StringLike, StringNotEquals, and StringNotLike.

Additionally, TagOperation had a placeholder DUMMY member instead of the three missing operations, and the resources array on BackupSelectionOptions mixes ARN resources with tag conditions in a way that implies per-ARN scoping that doesn't exist in the underlying API.

Description of changes

  • selection.ts: Replaces listOfTags: ListOfTags with a conditions: Conditions block in the generated CloudFormation. Four per-operation arrays (stringEquals, stringLike, stringNotEquals, stringNotLike) accumulate conditions and are serialized using PascalCase keys (required because conditions is typed as any in the generated layer, bypassing CDK's camelCase→PascalCase transformation). Extracts addTagCondition() as a shared private method.
  • selection.ts: Adds tagConditions?: TagCondition[] to BackupSelectionOptions. This is the preferred way to add tag-based filtering — it makes clear at the API level that conditions are selection-wide, not scoped to a single ARN.
  • resource.ts: Adds STRING_LIKE, STRING_NOT_EQUALS, STRING_NOT_LIKE to TagOperation; removes DUMMY. Deprecates BackupResource.fromTag() in favor of tagConditions.

BackupResource.fromTag() continues to work unchanged for backwards compatibility.

Describe any new or updated permissions being added

None.

Description of how you validated changes

  • Updated and created tests
  • Compiled the modified code and tested it manually

Checklist


This PR description was generated using Claude

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions Bot added bug This issue is a bug. p2 labels May 7, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team May 7, 2026 09:32
@github-actions github-actions Bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label May 7, 2026
@emfrab emfrab changed the title Fix/backup resource tags fix(backup): use Conditions instead of ListOfTags in BackupSelection May 7, 2026
Copy link
Copy Markdown
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@emfrab emfrab requested a review from aws-cdk-automation May 7, 2026 10:14
@aws-cdk-automation aws-cdk-automation dismissed their stale review May 7, 2026 10:16

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. p2

Projects

None yet

2 participants