fix(core): ensure CloudFormation ChangeSets receive tags with explicitStackTags flag#35212
fix(core): ensure CloudFormation ChangeSets receive tags with explicitStackTags flag#35212
Conversation
51ef95b to
c5741d2
Compare
…tStackTags flag When the @aws-cdk/core:explicitStackTags feature flag was introduced in v2.205.0, it inadvertently caused CloudFormation ChangeSets to not receive stack tags, breaking deployments with SCP policies requiring tags on ChangeSets. This fix adds a new property 'applyToChangeSets' to TagProps (default: true) that ensures tags are still applied to the stack for ChangeSet purposes, while maintaining the correct behavior of not duplicating tags on resources. Fixes regression introduced in v2.205.0 where ChangeSets lost their tags.
c5741d2 to
fc7663b
Compare
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
So, the diagnosis is:
- When the feature flag is set, we don't apply resource tags to Stacks. Instead, you need to set the Stack tags explicitly.
And the proposed remedy is:
- We add another flag to apply resource tags to stacks again.
- But we name it to be about "change sets" instead of about stacks.
Apart from the poor naming of the flag, this is all against the purpose of explicit stack tags.
The point of explicit stack tags, is that if you want to apply a tag to the Stack, you do it explicitly using the tags argument of the Stack properties:
new Stack(this, 'Stack', {
// Explicitly set the stack tags
tags: {
MyTag: 'MyValue',
}
});So there isn't really a problem, the old effect can still be achieved.
And if you really want the old behavior where resource tags are implicitly applied to stacks as well, set the feature flag to false (although this would not be my recommended solution).
|
Comments on closed issues and PRs are hard for our team to see. |
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