in src/lambda_codebase/account_processing/delete_default_vpc.py [0:0]
def delete_default_vpc(ec2_resource, ec2_client, default_vpc_id):
vpc = ec2_resource.Vpc(default_vpc_id)
LOGGER.info(f"Deleting gateways of VPC {default_vpc_id}")
for gateway in vpc.internet_gateways.all():
vpc.detach_internet_gateway(InternetGatewayId=gateway.id)
gateway.delete()
LOGGER.info(f"Deleting route tables associations of VPC {default_vpc_id}")
for route_table in vpc.route_tables.all():
for association in route_table.associations:
if not association.main:
association.delete()
LOGGER.info(f"Deleting security groups of VPC {default_vpc_id}")
for security_group in vpc.security_groups.all():
if security_group.group_name != "default":
security_group.delete()
LOGGER.info(f"Deleting subnets and interfaces of VPC {default_vpc_id}")
for subnet in vpc.subnets.all():
for interface in subnet.network_interfaces.all():
interface.delete()
subnet.delete()
LOGGER.info(f"Deleting default VPC {default_vpc_id}")
ec2_client.delete_vpc(VpcId=default_vpc_id)