EC2: Honor TagSpecifications in CreateTransitGatewayVpcAttachment - #264
Open
drauedo wants to merge 1 commit into
Open
EC2: Honor TagSpecifications in CreateTransitGatewayVpcAttachment#264drauedo wants to merge 1 commit into
drauedo wants to merge 1 commit into
Conversation
The create_transit_gateway_vpc_attachment response handler looked up the parsed TagSpecifications under the "transit-gateway-route-table" resource type (copy-pasted from the route table handler), so tags passed at creation time were silently dropped and only tags added later via CreateTags showed up in DescribeTransitGatewayVpcAttachments / DescribeTransitGatewayAttachments. Use the correct "transit-gateway-attachment" resource type (matching EC2_RESOURCE_TO_PREFIX) and add an aws_verified test covering create-time tags on both describe calls plus merging with tags added via CreateTags. Fixes SUP-138. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrkEvTCFkudp83ifsALDe9
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.
Fixes SUP-138.
Summary
Tags passed via
TagSpecificationsonCreateTransitGatewayVpcAttachmentwere silently dropped.DescribeTransitGatewayVpcAttachmentsandDescribeTransitGatewayAttachmentsreturned noTagsfor them, while tags added afterwards withCreateTagsworked. In LocalStack this surfaced as Terraform'saws_ec2_transit_gateway_vpc_attachmentre-adding itstagson every plan, and asAWS::EC2::TransitGatewayAttachmentin CloudFormation losing its tags (that resource provider also sendsTagSpecificationswithResourceType: transit-gateway-attachment).Root cause
moto/ec2/responses/transit_gateway_attachments.pyread the parsed tag specification with the wrong resource type key:_parse_tag_specification()returns a dict keyed byResourceType, so with the key copy-pasted from the route table handler the lookup always yielded{}. The correct type istransit-gateway-attachment(seeEC2_RESOURCE_TO_PREFIXinmoto/ec2/utils.py).Changes
transit-gateway-attachmentas the lookup key. One-line change, no other handlers touched.test_create_transit_gateway_vpc_attachment_with_tags(@pytest.mark.aws_verified+ec2_aws_verified(create_vpc=True, create_subnet=True, create_transit_gateway=True)). It asserts both create-time tags are present in the create response, inDescribeTransitGatewayVpcAttachments, and inDescribeTransitGatewayAttachments, and that a laterCreateTagsmerges with them. Without the fix it fails withKeyError: 'Tags'.Testing
pytest tests/test_ec2/test_transit_gateway.py: 37 passed (mocked).MOTO_TEST_ALLOW_AWS_REQUEST=true, us-east-1): the new test passed in 5m14s; all resources were cleaned up by the helper.PYTHONPATH): the original repro (aws ec2 create-transit-gateway-vpc-attachment --tag-specifications ...followed bydescribe-transit-gateway-vpc-attachments) now returns the create-time tags alongside theCreateTagsone, and the Terraform config no longer shows drift on the attachment'stags.Not in scope
DescribeTransitGatewayVpcAttachmentsandDescribeTransitGatewayAttachmentsstill ignoretag:filters (theirattr_pairshave no tag handling anddescribe_tag_filteris only applied for peering attachments). Pre-existing and separate from this bug.🤖 Generated with Claude Code
https://claude.ai/code/session_01JrkEvTCFkudp83ifsALDe9