Skip to content

Commit

Permalink
VPC cleanup: use DestinationIpv6CidrBlock when available
Browse files Browse the repository at this point in the history
  • Loading branch information
asmorodskyi committed Jan 29, 2024
1 parent 056c2c6 commit b56353a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions ocw/lib/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b56353a

Please sign in to comment.