Skip to content

feat(cfn): a stack records its own tags, and DescribeStacks reports them (#764) - #825

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

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

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

CreateStack's and UpdateStack's Tags.member.N was decoded by nothing at all. A caller
sending --tags Key=team,Value=platform got a 200 and a stack that reported no tags, so a
cost-allocation or policy assertion keyed on a stack tag had nothing to read, and there was no
way to tell a tagged stack from an untagged one.

Part of #764 — this half records and reports a stack's tags. Propagating them onto the
resources the stack creates is the other half and stays open.

What changed

CFNStackState gains a Tags field and cfnStackItem a Tags member, reported sorted by
key
as Parameters and Outputs already are, so a response is byte-identical across runs.
UpdateStack takes an options struct for the first time, which is the one non-obvious cost
here; a rollback of a failed update restores the tags the stack had, since a rollback converges
on the stack as it was.

The update semantics are AWS's, and they are why the tags are a map

If you don't specify this parameter, CloudFormation doesn't modify the stack's tags. If you
specify an empty value, CloudFormation removes all associated tags.

Three different requests, not two:

UpdateStack sends Result
no Tags parameter the stack keeps the tags it had
Tags= (an empty list) every tag is removed
Tags.member.N the tag set is replaced wholesale, not merged

The distinction is observable on the wire because the query protocol serialises an empty list
as a bare Tags= — botocore's _serialize_type_list, "The query protocol serializes empty
lists" — so --tags '[]' arrives with the parameter present and no members, where a request
that omits it arrives without it. A map[string]string where nil ≠ empty is what carries that
through to the resolver.

Two divergences, both AWS's own

  • A stack tag's value may not be empty. The Tag model's minimum is 1 and the member is
    Required: Yes, where IAM's and ELBv2's tag values document a minimum of 0. So Key=team
    with no value is refused by CloudFormation and accepted by those two.
  • The reserved aws: prefix is matched case-insensitively. CloudFormation is the only
    service in substrate that does, because it is the only one whose documentation says so: "The
    aws: prefix is reserved for AWS use. This prefix is case-insensitive." AWS:owner is
    refused as a stack tag and stays an ordinary caller tag in EC2, ELBv2 and IAM. The prefix is
    refused in a key only — of a value carrying it AWS says merely that "you can't update or
    delete the tag", a consequence rather than a refusal.

No character set is enforced: the Tag model publishes no Pattern for either member, unlike
IAM's and AWS Config's, and inventing one would refuse requests AWS accepts. The console page's
127 and 255 lose to the model's 128 and 256, and docs/services.md records the disagreement.

Provenance

The ValidationError/400 is substrate's choice, not AWS's. Neither operation's Errors list
names a code for a bad tag, and substrate's two precedents disagree — EC2 invents
InvalidParameterValue, ELBv2 accepts silently. ValidationError is what the plugin already
answers every other parameter refusal with. The refusal is of the whole request: a create with
one bad tag leaves no stack behind, and a refused update changes nothing. Validation lives on
the deployer's options rather than at the wire layer, so an in-process Client deploy is held
to the same limits as an HTTP request.

Compatibility

CreateStack/UpdateStack start refusing an aws:-prefixed tag key (any case), an empty key
or value, a key over 128 or a value over 256 characters, and more than 50 tags — where the tags
were previously ignored entirely. DescribeStacks gains a Tags member. CFNStackState gains
a field, additively: a stack recorded by an earlier version reads back with no tags.

Verification

Fail-before with the decoder neutered: 4 tests / 12 subtests red, and only
TestCFN_AStackWithNoTagsReportsAnEmptyTagList green — correctly, since it asserts the
no-tags case. Pass-after clean.

gofmt -l . / go build ./... / go vet ./...     clean
golangci-lint run ./...                        0 issues
make test                                      ok (go1.27.1)
GOTOOLCHAIN=go1.26.6 make test                 ok
GOTOOLCHAIN=go1.26.6 make coverage             emulator 83.8% (was 83.7%), total 83.1%
make docs-reference docs-reference-check docs-versions authz-reference-check   clean
npm --prefix docs run build                    ok
go vet -C test/e2e ./... && go test -C test/e2e ./...   ok

CreateChangeSet still drops Tags.member.N, filed as #824.

…hem (#764)

CreateStack's and UpdateStack's Tags.member.N was decoded by nothing at all: a
caller sending --tags Key=team,Value=platform got a 200 and a stack that reported
no tags, so a cost-allocation or policy assertion keyed on a stack tag had nothing
to read.

CFNStackState gains a Tags field and cfnStackItem a Tags member, reported sorted
by key as parameters and outputs already are. The update semantics are AWS's, and
they are why the tags are a map that can be absent rather than a list: omitting
the parameter preserves, an empty list clears, and sending members replaces the
set wholesale. UpdateStack takes an options struct for the first time.

Validation is against the Tag data type's own constraints — 50 tags, key 1-128,
value 1-256, counted in characters. Two divergences are AWS's own and asserted
rather than smoothed over: a stack tag's value may not be empty where IAM's and
ELBv2's may, and the reserved aws: prefix is matched case-insensitively, which
CloudFormation alone documents. The ValidationError/400 is substrate's choice and
recorded as such.
@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

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 9291637 into main Sep 12, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/764-stack-tags branch September 12, 2026 07:14
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.

1 participant