Add route.gateway-id filter for ec2:DescribeRouteTables (#5155)

This commit is contained in:
Brian Pandola 2022-05-22 02:43:51 -07:00 committed by GitHub
parent 096a89266c
commit ab756c82b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -76,6 +76,12 @@ class RouteTable(TaggedEC2Resource, CloudFormationModel):
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")

View File

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