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:explicitStackTags
feature 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
explicitStackTags
feature flag automatically addsaws:cdk:stack
to theexcludeResourceTypes
array 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
applyToChangeSets
property toTagProps
interface (default:true
)true
Enhanced
Tags.of(stack).add()
method to handle ChangeSet taggingexplicitStackTags
is enabled andapplyToChangeSets
istrue
(default), tags areapplied directly to the stack using
addStackTag()
applyToChangeSets: false
to disable this behavior if neededAdded comprehensive unit tests to verify the fix works correctly in all scenarios
Design Decisions:
applyToChangeSets
defaults totrue
to maintain existing behavior and fixthe regression automatically
Alternatives considered and rejected:
tags
aws:cdk:stack
inincludeResourceTypes
: 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:
explicitStackTags
is enabledapplyToChangeSets: false
explicitly disables ChangeSet taggingexplicitStackTags
is disabledaddStackTag()
continues to workManual Testing:
explicitStackTags
feature 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