def delete_default_vpc()

in src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/provisioner/src/vpc.py [0:0]


def delete_default_vpc(client, account_id, region, role):
    default_vpc_id = None
    max_retry_seconds = 360
    while True:
        try:
            vpc_response = client.describe_vpcs()
            break
        except exceptions.ClientError as e:
            if e.response["Error"]["Code"] == 'OptInRequired':
                LOGGER.warning(
                    f'Passing on region {client.meta.region_name} as Opt-in is required.')
                return
        except BaseException as e:
            LOGGER.warning(
                f'Could not retrieve VPCs: {e}. Sleeping for 2 seconds before trying again.')
            max_retry_seconds = + 2
            sleep(2)
            if max_retry_seconds <= 0:
                raise Exception(
                    "Could not describe VPCs within retry limit.",
                ) from e

    for vpc in vpc_response["Vpcs"]:
        if vpc["IsDefault"] is True:
            default_vpc_id = vpc["VpcId"]
            break

    if default_vpc_id is None:
        LOGGER.debug(
            f"No default VPC found in account {account_id} in the {region} region")
        return

    LOGGER.info(
        f"Found default VPC Id {default_vpc_id} in the {region} region")
    vpc_cleanup(account_id, default_vpc_id, role, region)