Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions moto/ec2/models/transit_gateway_route_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,16 @@ def create_transit_gateway_route(
}

if transit_gateway_attachment:
transit_gateway_attachment_dict = {
"transitGatewayAttachments": {
"resourceId": transit_gateway_attachment.resource_id,
"resourceType": transit_gateway_attachment.resource_type,
"transitGatewayAttachmentId": transit_gateway_attachment_id,
}
}
transit_gateways_route_table.routes[destination_cidr_block].update(
transit_gateway_attachment_dict # type: ignore
{
"transitGatewayAttachments": [ # type: ignore[dict-item]
{
"resourceId": transit_gateway_attachment.resource_id,
"resourceType": transit_gateway_attachment.resource_type,
"transitGatewayAttachmentId": transit_gateway_attachment_id,
}
]
}
)
return transit_gateways_route_table.routes[destination_cidr_block]

Expand Down
19 changes: 17 additions & 2 deletions tests/test_ec2/test_transit_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,19 @@ def test_search_transit_gateway_routes_by_routesearch():

exported_cidr_ranges = ["172.17.0.0/24", "192.160.0.0/24"]
for route in exported_cidr_ranges:
client.create_transit_gateway_route(
created_route = client.create_transit_gateway_route(
DestinationCidrBlock=route,
TransitGatewayRouteTableId=transit_gateway_route_id,
TransitGatewayAttachmentId=transit_gateway_attachment_id,
)
)["Route"]

assert created_route["TransitGatewayAttachments"] == [
{
"ResourceId": vpc["VpcId"],
"ResourceType": "vpc",
"TransitGatewayAttachmentId": transit_gateway_attachment_id,
}
]

for route in exported_cidr_ranges:
expected_route = client.search_transit_gateway_routes(
Expand All @@ -571,6 +579,13 @@ def test_search_transit_gateway_routes_by_routesearch():
)

assert expected_route["Routes"][0]["DestinationCidrBlock"] == route
assert expected_route["Routes"][0]["TransitGatewayAttachments"] == [
{
"ResourceId": vpc["VpcId"],
"ResourceType": "vpc",
"TransitGatewayAttachmentId": transit_gateway_attachment_id,
}
]


@mock_aws
Expand Down
Loading