fix(core): ensure CloudFormation ChangeSets receive tags with explicitStackTags flag #35212
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Issue # (if applicable)
Closes #35137.
Reason for this change
A regression was introduced in v2.205.0 where CloudFormation ChangeSets stopped receiving tags when
the
@aws-cdk/core:explicitStackTagsfeature flag is enabled. This breaks deployments inenvironments with SCP (Service Control Policy) policies that require specific tags to be present on
ChangeSets for compliance and governance purposes.
Description of changes
Root Cause:
The
explicitStackTagsfeature flag automatically addsaws:cdk:stackto theexcludeResourceTypesarray when using
Tags.of(stack).add(), which prevents tags from being applied to the stack itself.While this correctly prevents duplicate tagging of resources, it also prevents ChangeSets from
receiving the necessary tags.
Solution:
Added new
applyToChangeSetsproperty toTagPropsinterface (default:true)trueEnhanced
Tags.of(stack).add()method to handle ChangeSet taggingexplicitStackTagsis enabled andapplyToChangeSetsistrue(default), tags areapplied directly to the stack using
addStackTag()applyToChangeSets: falseto disable this behavior if neededAdded comprehensive unit tests to verify the fix works correctly in all scenarios
Design Decisions:
applyToChangeSetsdefaults totrueto maintain existing behavior and fixthe regression automatically
Alternatives considered and rejected:
tags
aws:cdk:stackinincludeResourceTypes: Would re-introduce the duplicatetagging problem
Describe any new or updated permissions being added
No new IAM permissions are required. This change only affects how existing tags are applied to
CloudFormation ChangeSets.
Description of how you validated changes
Unit Tests Added:
explicitStackTagsis enabledapplyToChangeSets: falseexplicitly disables ChangeSet taggingexplicitStackTagsis disabledaddStackTag()continues to workManual Testing:
explicitStackTagsfeature flagChecklist
GUIDE and DESIGN
GUIDELINES
By submitting this pull request, I confirm that my contribution is made under the terms of the
Apache-2.0 license