Repository: getmoto/moto

Issue:
Implement filter 'route.vpc-peering-connection-id' for DescribeRouteTables
Hi, when I try to mock the DescribeRouteTables I got the following error.

`FilterNotImplementedError: The filter 'route.vpc-peering-connection-id' for DescribeRouteTables has not been implemented in Moto yet. Feel free to open an issue at https://github.com/spulec/moto/issues
`

It would be nice to add this filter to moto, thanks!


Discussion:

Resolving patch:
diff --git a/moto/ec2/models/route_tables.py b/moto/ec2/models/route_tables.py
--- a/moto/ec2/models/route_tables.py
+++ b/moto/ec2/models/route_tables.py
@@ -86,6 +86,12 @@ def get_filter_value(self, filter_name):
                 for route in self.routes.values()
                 if route.gateway is not None
             ]
+        elif filter_name == "route.vpc-peering-connection-id":
+            return [
+                route.vpc_pcx.id
+                for route in self.routes.values()
+                if route.vpc_pcx is not None
+            ]
         else:
             return super().get_filter_value(filter_name, "DescribeRouteTables")
 


Test patch:
diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py
--- a/tests/test_ec2/test_route_tables.py
+++ b/tests/test_ec2/test_route_tables.py
@@ -204,6 +204,58 @@ def test_route_tables_filters_associations():
     subnet_route_tables[0]["Associations"].should.have.length_of(2)
 
 
+@mock_ec2
+def test_route_tables_filters_vpc_peering_connection():
+    client = boto3.client("ec2", region_name="us-east-1")
+    ec2 = boto3.resource("ec2", region_name="us-east-1")
+    vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
+    main_route_table_id = client.describe_route_tables(
+        Filters=[
+            {"Name": "vpc-id", "Values": [vpc.id]},
+            {"Name": "association.main", "Values": ["true"]},
+        ]
+    )["RouteTables"][0]["RouteTableId"]
+    main_route_table = ec2.RouteTable(main_route_table_id)
+    ROUTE_CIDR = "10.0.0.4/24"
+
+    peer_vpc = ec2.create_vpc(CidrBlock="11.0.0.0/16")
+    vpc_pcx = ec2.create_vpc_peering_connection(VpcId=vpc.id, PeerVpcId=peer_vpc.id)
+
+    main_route_table.create_route(
+        DestinationCidrBlock=ROUTE_CIDR, VpcPeeringConnectionId=vpc_pcx.id
+    )
+
+    # Refresh route table
+    main_route_table.reload()
+    new_routes = [
+        route
+        for route in main_route_table.routes
+        if route.destination_cidr_block != vpc.cidr_block
+    ]
+    new_routes.should.have.length_of(1)
+
+    new_route = new_routes[0]
+    new_route.gateway_id.should.equal(None)
+    new_route.instance_id.should.equal(None)
+    new_route.vpc_peering_connection_id.should.equal(vpc_pcx.id)
+    new_route.state.should.equal("active")
+    new_route.destination_cidr_block.should.equal(ROUTE_CIDR)
+
+    # Filter by Peering Connection
+    route_tables = client.describe_route_tables(
+        Filters=[{"Name": "route.vpc-peering-connection-id", "Values": [vpc_pcx.id]}]
+    )["RouteTables"]
+    route_tables.should.have.length_of(1)
+    route_table = route_tables[0]
+    route_table["RouteTableId"].should.equal(main_route_table_id)
+    vpc_pcx_ids = [
+        route["VpcPeeringConnectionId"]
+        for route in route_table["Routes"]
+        if "VpcPeeringConnectionId" in route
+    ]
+    all(vpc_pcx_id == vpc_pcx.id for vpc_pcx_id in vpc_pcx_ids)
+
+
 @mock_ec2
 def test_route_table_associations():
     client = boto3.client("ec2", region_name="us-east-1")