Skip to content

Commit

Permalink
Add route.gateway-id filter for ec2:DescribeRouteTables (#5155)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpandola authored May 22, 2022
1 parent 096a892 commit ab756c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions moto/ec2/models/route_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def get_filter_value(self, filter_name):
return self.associations.keys()
elif filter_name == "association.subnet-id":
return self.associations.values()
elif filter_name == "route.gateway-id":
return [
route.gateway.id
for route in self.routes.values()
if route.gateway is not None
]
else:
return super().get_filter_value(filter_name, "DescribeRouteTables")

Expand Down
12 changes: 12 additions & 0 deletions tests/test_ec2/test_route_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def test_route_tables_filters_standard():

vpc2 = ec2.create_vpc(CidrBlock="10.0.0.0/16")
route_table2 = ec2.create_route_table(VpcId=vpc2.id)
igw = ec2.create_internet_gateway()
route_table2.create_route(DestinationCidrBlock="10.0.0.4/24", GatewayId=igw.id)

all_route_tables = client.describe_route_tables()["RouteTables"]
all_ids = [rt["RouteTableId"] for rt in all_route_tables]
Expand Down Expand Up @@ -135,6 +137,16 @@ def test_route_tables_filters_standard():
vpc2_main_route_table_ids.should_not.contain(route_table1.id)
vpc2_main_route_table_ids.should_not.contain(route_table2.id)

# Filter by route gateway id
resp = client.describe_route_tables(
Filters=[
{"Name": "route.gateway-id", "Values": [igw.id]},
]
)["RouteTables"]
assert any(
[route["GatewayId"] == igw.id for table in resp for route in table["Routes"]]
)

# Unsupported filter
if not settings.TEST_SERVER_MODE:
# ServerMode will just throw a generic 500
Expand Down

0 comments on commit ab756c8

Please sign in to comment.