Skip to content

EC2: Honor TagSpecifications in CreateTransitGatewayVpcAttachment - #264

Open
drauedo wants to merge 1 commit into
localstackfrom
fix/ec2-tgw-vpc-attachment-tag-specifications
Open

EC2: Honor TagSpecifications in CreateTransitGatewayVpcAttachment#264
drauedo wants to merge 1 commit into
localstackfrom
fix/ec2-tgw-vpc-attachment-tag-specifications

Conversation

@drauedo

@drauedo drauedo commented Sep 2, 2026

Copy link
Copy Markdown

Fixes SUP-138.

Summary

Tags passed via TagSpecifications on CreateTransitGatewayVpcAttachment were silently dropped. DescribeTransitGatewayVpcAttachments and DescribeTransitGatewayAttachments returned no Tags for them, while tags added afterwards with CreateTags worked. In LocalStack this surfaced as Terraform's aws_ec2_transit_gateway_vpc_attachment re-adding its tags on every plan, and as AWS::EC2::TransitGatewayAttachment in CloudFormation losing its tags (that resource provider also sends TagSpecifications with ResourceType: transit-gateway-attachment).

Root cause

moto/ec2/responses/transit_gateway_attachments.py read the parsed tag specification with the wrong resource type key:

tags = self._parse_tag_specification().get("transit-gateway-route-table", {})

_parse_tag_specification() returns a dict keyed by ResourceType, so with the key copy-pasted from the route table handler the lookup always yielded {}. The correct type is transit-gateway-attachment (see EC2_RESOURCE_TO_PREFIX in moto/ec2/utils.py).

Changes

  • Use transit-gateway-attachment as the lookup key. One-line change, no other handlers touched.
  • Add 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, in DescribeTransitGatewayVpcAttachments, and in DescribeTransitGatewayAttachments, and that a later CreateTags merges with them. Without the fix it fails with KeyError: 'Tags'.

Testing

  • pytest tests/test_ec2/test_transit_gateway.py: 37 passed (mocked).
  • Against real AWS (MOTO_TEST_ALLOW_AWS_REQUEST=true, us-east-1): the new test passed in 5m14s; all resources were cleaned up by the helper.
  • LocalStack Pro (host mode with this moto on PYTHONPATH): the original repro (aws ec2 create-transit-gateway-vpc-attachment --tag-specifications ... followed by describe-transit-gateway-vpc-attachments) now returns the create-time tags alongside the CreateTags one, and the Terraform config no longer shows drift on the attachment's tags.

Not in scope

DescribeTransitGatewayVpcAttachments and DescribeTransitGatewayAttachments still ignore tag: filters (their attr_pairs have no tag handling and describe_tag_filter is only applied for peering attachments). Pre-existing and separate from this bug.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JrkEvTCFkudp83ifsALDe9

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
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