Repository navigation
feat(cfn): a stack's own tags reach the resources it creates (#764) - #831
Merged
Merged
Conversation
`CreateStack`'s `Tags` member does two things and substrate did one of them: "CloudFormation also propagates these tags to the resources created in the stack." Every resource the `aws:cloudformation:*` stamp reaches now carries the stack's tags too, readable through the owning service's own tag call. Whose tag a key is is decided by the stack's *previous* tag set: a stored value equal to what the stack previously propagated is the stack's own, to overwrite or remove; anything else is the caller's, and is left alone. No new bookkeeping, and it cannot delete a key the stack never propagated. The one undecidable case — a caller who set the same value the stack propagates — is documented rather than papered over. Propagation runs once over the finished deployment rather than per resource, because a redeploy's already-exists refusal is cleared only after every resource has dispatched: at stamp time an unchanged resource still looks failed, and it is exactly those an added stack tag must reach. Their physical ID comes from the previous stack record, sound because the refusal was cleared only for an identical declaration.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #764.
The first half of #764 (shipped in this milestone) recorded a stack's tags and reported them on
DescribeStacks. This is the other half, which is where AWS states the point of the member onCreateStackitself:Until now none of them did. A caller who tagged a stack
team=platformfor a cost report, or wrote a policy conditioned onaws:ResourceTag/team, saw the tag on the stack and on nothing the stack built.Every resource the
aws:cloudformation:*stamp reaches (#765) now carries the stack's tags too — S3 buckets, Lambda functions, SQS queues, DynamoDB tables, all nine EC2 kinds and all four ELBv2 kinds — and each is asserted by reading back through the owning service's own tag call (GetBucketTagging,ListTags,ListQueueTags,ListTagsOfResource, EC2's and ELBv2'sDescribeTags), because a tag written to a state key the service does not read would satisfy a state assertion and no caller. A resource whose service models no tags is skipped in the same silence as the stamp, on the same authority: "The propagation of stack-level tags to resources, including tags with theaws:prefix, varies by resource type."Whose tag a key is
The hard part is not the write. A propagated tag must not clobber one the caller set directly on a resource, and a stack tag whose value the caller changes must still reach the resource — two requirements pulling opposite ways, and neither decidable from the new tag set alone.
What decides it is the stack's previous tag set, which #764's first half already stores on
CFNStackState:No new bookkeeping, and it can never delete a key the stack never propagated. The single case it cannot tell apart — a caller who set a resource tag to the same value the stack propagates loses it when the stack tag goes away — is recorded in
docs/services.mdrather than papered over: the alternative is per-resource tag provenance in the event stream, for an ambiguity AWS does not resolve either (it publishes no provenance for a propagated tag).Why propagation runs once over the finished deployment
Not per resource beside the stamp, because of a redeploy. A resource whose declaration did not change is refused with an already-exists error that
clearUnchangedRedeploysonly clears after every resource has dispatched — so at stamp time an unchanged resource still looks failed, and it is exactly the resources an update does not touch that a newly added stack tag has to reach. A refused create also returns no physical ID at all, so the identifier comes from the previous stack record; that is sound precisely because the refusal was cleared only for a declaration that was identical.One consequence worth knowing, and why the update tests use named resources: an update re-creates a resource the template does not name, so an unnamed VPC gets fresh tags rather than retagged ones, while a named bucket or queue is retagged in place.
Tests
emulator/cfn_stack_tag_propagation_test.go, five tests over #764's remaining criteria:aws:cloudformation:*keys stay;Tagschanges nothing on any resource — the preserved set is not re-derived into something else;TagQueuesurvives both a stack tag of the same name changing value and the key being dropped from the stack, while the untouched resource beside it tracks the stack;Fail-before proven: stubbing out the deployer's reconcile fails exactly these five and nothing else.
Docs
docs/services.mdgains A stack tag reaches the resources the stack creates under the stack-tags section — AWS's quote, the ownership table above, the undecidable case, and the three consequences. Two now-falsified claims are corrected: the bullet saying stack tags do not reach resources, and the ELB section's statement that the stamp covers EC2 only (a template's resource-level ELB tags are still dropped, which is what that paragraph now says).Verification
gofmt/go build/go vetclean;golangci-lint run ./...0 issues;make testandGOTOOLCHAIN=go1.26.6 make testpass with-race; coverage emulator 83.7% / total 83.1%;make docs-reference docs-reference-check docs-versions authz-reference-check,npm --prefix docs run build, and the e2e vet+test all pass.