def vpc(function, credentials, unused_resource_count, region_list):
    print('Scanning VPCs')
    vpc_count = 0
    unused_vpc_detail = []
    for region in region_list:
        try:
            ec2 = boto3.resource('ec2', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], region_name=region)
            vpcs = list(ec2.vpcs.all())
            network_interfaces = list(ec2.network_interfaces.all())
            all_vpcs = set([vpc.vpc_id for vpc in vpcs])
            all_active_vpcs = set([vpc['VpcId'] for ni in network_interfaces for vpc in ni.vpc])
            unused_vpcs = (all_vpcs - all_active_vpcs)
            for vpcid in unused_vpcs:
                unused_vpc_detail.append({'ResourceType': 'AWS::EC2::VPC', 'ResourceId': vpcid, 'Region': region})
            vpc_count += len(unused_vpcs)
        except:
            pass
    if vpc_count:
        unused_vpc_detail = json.loads(json.dumps(unused_vpc_detail))
        f = csv.writer(open('./aws_logs/vpc.csv', 'w', newline=''))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_vpc_detail in unused_vpc_detail:
            f.writerow([unused_vpc_detail['ResourceType'], unused_vpc_detail['ResourceId'], unused_vpc_detail['Region']])
    unused_resource_count[function] = vpc_count
def vpc(function, credentials, unused_resource_count, region_list):
    print('Scanning VPCs')
    vpc_count = 0
    unused_vpc_detail = []
    for region in region_list:
        try:
            ec2 = boto3.resource('ec2', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], region_name=region)
            vpcs = list(ec2.vpcs.all())
            network_interfaces = list(ec2.network_interfaces.all())
            all_vpcs = set([vpc.vpc_id for vpc in vpcs])
            all_active_vpcs = set([vpc['VpcId'] for ni in network_interfaces for vpc in ni.vpc])
            unused_vpcs = (all_vpcs - all_active_vpcs)
            for vpcid in unused_vpcs:
                unused_vpc_detail.append({'ResourceType': 'AWS::EC2::VPC', 'ResourceId': vpcid, 'Region': region})
            vpc_count += len(unused_vpcs)
        except:
            pass
    if vpc_count:
        unused_vpc_detail = json.loads(json.dumps(unused_vpc_detail))
        f = csv.writer(open('./aws_logs/vpc.csv', 'w', newline=))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_vpc_detail in unused_vpc_detail:
            f.writerow([unused_vpc_detail['ResourceType'], unused_vpc_detail['ResourceId'], unused_vpc_detail['Region']])
    unused_resource_count[function] = vpc_count