Skip to content

feat(cfn): a stack's own tags reach the resources it creates (#764) - #831

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/764-propagate-stack-tags
Sep 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/764-propagate-stack-tags

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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 on CreateStack itself:

Key-value pairs to associate with this stack. CloudFormation also propagates these tags to the resources created in the stack.

Until now none of them did. A caller who tagged a stack team=platform for a cost report, or wrote a policy conditioned on aws: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's DescribeTags), 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 the aws: 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:

the resource's stored value for a key what happens
absent written
equal to the value the stack carried before overwritten with the new value
anything else left alone — it is the caller's
key left the stack, stored value still matches removed
key left the stack, stored value differs left alone

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.md rather 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 clearUnchangedRedeploys only 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:

  • a stack tag reaches all seven stampable kinds, one subtest each (a single stack-wide assertion would let a type the switch does not claim pass silently);
  • an update that adds, changes and removes a tag lands all three on both a bucket and a queue, through two different tag stores, while the three aws:cloudformation:* keys stay;
  • an update that omits Tags changes nothing on any resource — the preserved set is not re-derived into something else;
  • a tag the caller set directly through TagQueue survives 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;
  • a stack tag on a service that models no tags is skipped with nothing logged (asserted on the log, since a silent skip is not observable otherwise).

Fail-before proven: stubbing out the deployer's reconcile fails exactly these five and nothing else.

Docs

docs/services.md gains 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 vet clean; golangci-lint run ./... 0 issues; make test and GOTOOLCHAIN=go1.26.6 make test pass 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.

`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.
@scttfrdmn scttfrdmn added this to the v0.113.0 milestone Sep 12, 2026
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.08696% with 33 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cfn_stack_tag_propagation.go 82.07% 19 Missing ⚠️
emulator/cfn_deployer.go 56.25% 14 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 2c7bf62 into main Sep 12, 2026
16 of 17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/764-propagate-stack-tags branch September 12, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cfn: CreateStack's Tags.member.N is dropped, and nothing propagates a stack tag to its resources

1 participant