diff --git a/ocw/lib/ec2.py b/ocw/lib/ec2.py index a14b258b..dab2b383 100644 --- a/ocw/lib/ec2.py +++ b/ocw/lib/ec2.py @@ -253,10 +253,18 @@ def delete_routing_tables(self, region: str, vpc_id: str) -> None: if self.dry_run: self.log_info(f"{route_table['RouteTableId']} route will not be deleted due to dry_run mode") self.log_dbg(route) - else: + elif 'DestinationCidrBlock' in route: + self.log_info(f"Delete route {route_table['RouteTableId']}") + self.log_dbg(route) + self.ec2_client(region).delete_route(RouteTableId=route_table['RouteTableId'], + DestinationCidrBlock=route['DestinationCidrBlock']) + elif 'DestinationIpv6CidrBlock' in route: self.log_info(f"Delete route {route_table['RouteTableId']}") self.log_dbg(route) - self.ec2_client(region).delete_route(RouteTableId=route_table['RouteTableId']) + self.ec2_client(region).delete_route(RouteTableId=route_table['RouteTableId'], + DestinationIpv6CidrBlock=route['DestinationIpv6CidrBlock']) + else: + raise RuntimeError(f'Failed to delete {route}') if route_table['Associations'] == []: if self.dry_run: self.log_info(f"{route_table['RouteTableId']} routing table will not be deleted due to dry_run mode") diff --git a/tests/test_ec2.py b/tests/test_ec2.py index c401b09e..947d2984 100644 --- a/tests/test_ec2.py +++ b/tests/test_ec2.py @@ -170,7 +170,7 @@ def disassociate_route_table(self, AssociationId): def describe_route_tables(self, Filters): return MockedEC2Client.routing_tables - def delete_route(self, RouteTableId): + def delete_route(self, RouteTableId, DestinationCidrBlock = None, DestinationIpv6CidrBlock = None): if RouteTableId == '2': MockedEC2Client.delete_route_called = True