def iam_group(function, credentials, unused_resource_count, region_list):
    print('Scanning IAM Groups')
    iamgroup_count = 0
    unused_iamgroup_detail = []
    try:
        iam = boto3.resource('iam', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'])
        iam_client = boto3.client('iam', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'])
        iamgroup_data = list(iam.groups.all())
        for group in iamgroup_data:
            if (not iam_client.get_group(GroupName=group.name)['Users']):
                unused_iamgroup_detail.append({'ResourceType': 'AWS::IAM::Group', 'ResourceId': group.name, 'Region': 'Global'})
                iamgroup_count += 1
    except:
        pass
    if iamgroup_count:
        unused_iamgroup_detail = json.loads(json.dumps(unused_iamgroup_detail))
        f = csv.writer(open('./aws_logs/iam_group.csv', 'w', newline=''))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_iamgroup_detail in unused_iamgroup_detail:
            f.writerow([unused_iamgroup_detail['ResourceType'], unused_iamgroup_detail['ResourceId'], unused_iamgroup_detail['Region']])
    unused_resource_count[function] = iamgroup_count
def iam_group(function, credentials, unused_resource_count, region_list):
    print('Scanning IAM Groups')
    iamgroup_count = 0
    unused_iamgroup_detail = []
    try:
        iam = boto3.resource('iam', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'])
        iam_client = boto3.client('iam', aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'])
        iamgroup_data = list(iam.groups.all())
        for group in iamgroup_data:
            if (not iam_client.get_group(GroupName=group.name)['Users']):
                unused_iamgroup_detail.append({'ResourceType': 'AWS::IAM::Group', 'ResourceId': group.name, 'Region': 'Global'})
                iamgroup_count += 1
    except:
        pass
    if iamgroup_count:
        unused_iamgroup_detail = json.loads(json.dumps(unused_iamgroup_detail))
        f = csv.writer(open('./aws_logs/iam_group.csv', 'w', newline=))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_iamgroup_detail in unused_iamgroup_detail:
            f.writerow([unused_iamgroup_detail['ResourceType'], unused_iamgroup_detail['ResourceId'], unused_iamgroup_detail['Region']])
    unused_resource_count[function] = iamgroup_count