Skip to content

feat(ec2): CreateTags reaches every taggable resource type (#708) - #721

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/708-createtags-all-types
Aug 22, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/708-createtags-all-types

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #708

CreateTags resolved ten ID prefixes and silently ignored the rest. A request naming an ami-, lt-, fleet-, pg- or key- ID answered <return>true</return> and wrote nothing — every one of the five was well-formed and named a resource substrate stores, so the answer was indistinguishable from success. ec2TaggableResource now resolves fifteen prefixes, and ec2TagScanTargets reports the same fifteen, so DescribeTags and CreateTags cover exactly the same set. They did not: three types could be read and not written, and placement-group and key-pair could be neither — both were absent from the scan too.

Corrections to the issue body

  • "every one names a record that already stores a tags member" — false for key-pair. EC2KeyPair had no Tags field. Added, spelled "tags" like every other record so applyTagsToResource and scanTags find it.
  • "DescribeTags already reports tags on all of them" — false for placement-group and key-pair. Neither was in ec2TagScanTargets, and both are keyed by name, so the scan needed idMember to read the ID out of the record rather than reporting the key's tail.
  • A launch template's own tags were settable by no path at all. The TagSpecification createLaunchTemplate read lives inside LaunchTemplateData and is AWS's "tags for the resources that are created when an instance is launched" — a different parameter from the top-level TagSpecification.N, "the tags to apply to the launch template on creation. To tag the launch template, the resource type must be launch-template". Both are read now, each on its own scope.

Two things the tests caught

xml:"tagSet>item,omitempty" cannot omit an element. encoding/xml writes the parent of a nested path even for a nil slice, so every untagged key pair, placement group and launch template answered <tagSet></tagSet>. AWS's CreateLaunchTemplate Example 1 and CreatePlacementGroup Example 2 each create an untagged resource and neither response carries a tagSet at all, while CreateKeyPair's tagged example does. Fixed with a pointer-to-wrapper struct — which ec2_subnet_filters.go had already discovered for #685, so the two converged on one shared ec2TagSetXML rather than shipping the struct twice.

Refusing inside the apply loop leaves a partially-tagged state. ec2CheckTagResourceIDs runs over every ResourceId.N before the first tag is written, so a request naming a good instance ID first and a bad ID second tags neither. TestEC2_CreateTags_RefusesBeforeTaggingAnything fails against the refuse-in-the-loop shape.

Behaviour changes

Change Justification
An untaggable prefix answers InvalidID / 400 instead of <return>true</return> AWS publishes the code and description in the EC2 client-error table
Seven responses omit tagSet when a resource has no tags AWS's own untagged examples for those operations
ami- and snap- authorize against an account-less ARN arn:${Partition}:ec2:${Region}::image/${ImageId} is what AWS publishes

DescribeFleets keeps the empty element deliberately: its API reference page publishes no example response, so there is no untagged sample to follow and changing it would be substrate guessing rather than reading. DescribeSnapshots keeps its present-but-empty element because its own page shows it. Each response answers to the page that documents it.

Provenance

  • InvalidID's code and description are AWS's, but from the client-error table — API_CreateTags.html publishes no operation-specific error at all. Naming the offending ID where AWS writes "The specified ID" is substrate's.
  • Whether real CreateTags takes a placement group by ID or by name is not settled by AWS. The ARN is by name and DescribePlacementGroups publishes no group-id filter, but the client-error table publishes InvalidPlacementGroupId.Malformed "in the form pg-xxxxxxxxxxxxxxxxx", which only an ID-taking operation can raise. Substrate accepts the pg- form and translates.

Verification

gofmt / go build / go vet / golangci-lint clean; make test green with race; coverage 83.1% on emulator (82.4% total); make docs-reference docs-reference-check docs-versions; docs site builds with no missing anchors; test/e2e green.

The authz-layer suite went from nine resource types to all fifteen. Mutating the ARN builders — stamping the account onto image/snapshot, and naming the placement group by ID instead of by name — turns exactly those three subtests red, so the new rows bite.

A live AWS CLI run against a built binary confirms the wire shapes: tagged and untagged CreateKeyPair/CreatePlacementGroup/CreateLaunchTemplate (untagged decode to Tags: null, tagged to the tags), CreateTags over all five new types followed by DescribeTags reporting each under the right resourceType and the ID the caller passed, the InvalidID refusal, and DeleteTags clearing them again.

Five ID prefixes were silently ignored: a CreateTags naming an ami-, lt-,
fleet-, pg- or key- ID answered <return>true</return> and wrote nothing.
Each was well-formed and named a resource substrate stores, so a caller
had no way to tell — the answer is the one a successful call gives.

ec2TaggableResource now resolves fifteen prefixes and ec2TagScanTargets
reports the same fifteen, so DescribeTags and CreateTags cover exactly
the same set; previously three types could be read and not written, and
placement-group and key-pair could be neither.

A launch template's own tags were settable by no path at all: the
TagSpecification CreateLaunchTemplate read lives inside LaunchTemplateData
and is scoped to what a launch creates. The top-level TagSpecification.N
scoped to launch-template is now read as well.

EC2KeyPair gained a Tags field, CreateKeyPair/ImportKeyPair/
CreatePlacementGroup honour TagSpecification.N, and DescribeKeyPairs/
DescribePlacementGroups render tagSet.

An ID whose prefix names no taggable type is now refused with InvalidID
over every ResourceId.N before the first tag is applied, rather than
ignored. A well-formed prefix naming nothing stays a no-op at 200.

Seven responses omit tagSet for an untagged resource instead of rendering
<tagSet></tagSet>, following AWS's own untagged examples;
xml:"tagSet>item,omitempty" cannot express the absence, so they converged
on the pointer wrapper #685 wrote for DescribeSubnets, now ec2TagSetXML.
DescribeFleets keeps the old shape — its page publishes no example
response — and DescribeSnapshots keeps its empty element, which its own
page shows.

Fixed alongside: an ami- and a snap- ID are authorized against the
account-less ARN AWS documents, where the authorizer stamped the account
on unconditionally and made an ARN-scoped Deny inert (#689's arm had it).

Closes #708
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.14097% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_plugin.go 82.12% 16 Missing and 16 partials ⚠️
emulator/ec2_describetags.go 84.61% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 624c021 into main Aug 22, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/708-createtags-all-types branch August 22, 2026 01:25
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.

ec2: CreateTags cannot reach an image, launch template, fleet, placement group or key pair

1 participant