Skip to content

feat(cfn): the aws:cloudformation:* stamp reaches beyond EC2 (#765) - #828

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/765-stamp-beyond-ec2
Sep 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/765-stamp-beyond-ec2

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #765.

The defect

StackDeployer.stampCFNResourceTags resolved a physical ID to a state key with
ec2TaggableResource — a prefix switch over fifteen EC2 id forms. That covers every EC2 type
the deployer creates and nothing else, so most of a stack was unstamped: an S3 bucket, a Lambda
function, an SQS queue, a DynamoDB table and every ELBv2 resource carried none of
aws:cloudformation:stack-name, …:stack-id or …:logical-id. A policy conditioned on
aws:ResourceTag/aws:cloudformation:stack-name — the shape AWS's own bundled cleanup policy
uses — matched nothing on them, and neither did a cost-allocation assertion.

What changed

Nine types across six services are stamped now: EC2's nine as before, plus AWS::S3::Bucket,
AWS::Lambda::Function, AWS::SQS::Queue, AWS::DynamoDB::Table and ELBv2's LoadBalancer,
TargetGroup, Listener and ListenerRule.

New emulator/cfn_resource_tags.go holds the second resolver, keyed on
DeployedResource.Type rather than on the physical ID's shape. That is not a style choice:
outside EC2 a physical ID is a bare name, so a bucket named orders and a queue named orders
are the same string and there is nothing in the ID to switch on. The CFN type is already carried
beside it, so this needed no new bookkeeping. ELBv2 is resolved separately through
elbResolveTaggedResource, because its four kinds are keyed by a generated suffix that is not
derivable from a name.

TaggingPlugin.mergeTags is extracted into mergeResourceTags, a free function taking a
StateManager, following ec2ApplyTagsToResource's precedent — so the Resource Groups Tagging
API and the deployer cannot drift into two merge behaviours. The method now delegates to it.

stampCFNResourceTags tries EC2's resolver first, then the new one, and still returns in
silence when neither claims the resource.

Every key was verified against the plugin that owns it

TaggingPlugin.resolveARN computes a key for the same four services and gets SQS wrong: it
addresses queue:<name> where the SQS plugin writes queue:<account>/<name>, so a tag set
through TagResources is invisible to ListQueueTags — and to GetResources, which lists by
prefix and so reads the real record. Filed as #826, and deliberately not reproduced here. The
tie-breaker is #765's own criterion: the record the service's own tag call loads is the record
the stamp has to land in.

That is why every assertion in the tests reads the tag back through the owning service's tag
call rather than out of state. A state assertion would have passed against the wrong key.

Provenance, corrected

An earlier note in cfn_deployer.go and docs/services.md said only
aws:cloudformation:stack-name appeared on any reachable AWS page and that the three-key set
was observed behaviour. The Template Reference's Resource tag page documents all three by
name; the pages consulted when #746 shipped had returned empty bodies. The same page supplies
the sentence that licenses a partial cut rather than an exhaustive list:

The propagation of stack-level tags to resources, including tags with the aws: prefix,
varies by resource type. For example, tags aren't propagated to Amazon EBS volumes that
are created from block device mappings.

So docs/services.md states substrate's rule — a resource is stamped when substrate models tags
for its service — and names the ~20 services skipped because they keep no tag state, plus API
Gateway and Cognito, which carry tag state with no operation to read it back through (#819).
IAM is excluded on purpose: no page says an IAM entity receives the stamp, and TagRole refuses
an aws:-prefixed key, so a stamped IAM tag would be one no caller could set or remove.

Tests

emulator/cfn_stamp_beyond_ec2_test.go is new; newCFNStampFixture grew from two plugins to
seven, because the plugin owning each record has to be present to answer for it.

  • one subtest per service, each read through GetBucketTagging, ListTags, ListQueueTags,
    ListTagsOfResource and ELBv2 DescribeTags, plus EC2 to pin that its resolver still wins;
  • a listener and a rule, the pair whose physical ID is an ARN, with the parent's tags asserted
    afterwards so a prefix match rather than an exact one would be caught;
  • a CloudWatch Logs log group deploys clean with nothing logged, asserted against a recording
    logger since a silent skip is not observable any other way;
  • a policy on aws:ResourceTag/aws:cloudformation:stack-name allows a DeleteBucket for a
    matching stack's bucket and refuses it for another's — cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765's fourth criterion, and it goes
    through a different reader (AuthController.resourceTagsFor) than the assertions above;
  • TestCFN_ANonEC2ResourceIsNotStamped is inverted into
    TestCFN_ANonEC2ResourceIsStampedByItsOwnService. The old assertion read through EC2's
    DescribeTags, so it would have passed unchanged — a bucket carries no EC2 tags either way.

Fail-before: stubbing cfnStampResourceTags to return false, nil turns 4 tests and 6
subtests red. The EC2 subtest and the silent-skip test stay green, which is correct — neither
depends on the new resolver.

Filed in passing

Verification

gofmt, go build, go vet, golangci-lint (0 issues), make test and GOTOOLCHAIN=go1.26.6 make test all clean. Coverage holds at emulator 83.8% / total 83.1%. make docs-reference docs-reference-check docs-versions authz-reference-check, npm --prefix docs run build, and
go vet/go test -C test/e2e all pass.

The deployer's stamp resolved a physical ID with ec2TaggableResource, which
covers every EC2 type it creates and nothing else — so an S3 bucket, a Lambda
function, an SQS queue, a DynamoDB table and every ELBv2 resource a stack
created carried none of the three aws:cloudformation:* keys, and a policy or a
cost-allocation assertion keyed on the stack name saw nothing on them.

A second resolver keys on the CloudFormation resource type rather than on the
physical ID's shape, because outside EC2 a physical ID is a bare name with
nothing to switch on. Every state key is verified against the plugin that owns
the record rather than copied from TaggingPlugin.resolveARN, which gets SQS
wrong (#826). TaggingPlugin.mergeTags is extracted into a free function so the
tagging API and the deployer share one merge.
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.76190% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cfn_resource_tags.go 88.00% 6 Missing ⚠️
emulator/tagging_plugin.go 76.00% 6 Missing ⚠️
emulator/cfn_deployer.go 44.44% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 414f8ac into main Sep 12, 2026
16 of 17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/765-stamp-beyond-ec2 branch September 12, 2026 07:44
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: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped

1 participant