def iam_user(function, credentials, unused_resource_count, region_list):
    print('Scanning IAM Users')
    iamuser_count = 0
    unused_iamuser_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'])
        iamuser_data = list(iam.users.all())
        for user in iamuser_data:
            if ((not user.password_last_used) and (not iam_client.list_access_keys(UserName=user.name)['AccessKeyMetadata'])):
                unused_iamuser_detail.append({'ResourceType': 'AWS::IAM::User', 'ResourceId': user.name, 'Region': 'Global'})
                iamuser_count += 1
    except:
        pass
    if iamuser_count:
        unused_iamuser_detail = json.loads(json.dumps(unused_iamuser_detail))
        f = csv.writer(open('./aws_logs/iam_user.csv', 'w', newline=''))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_iamuser_detail in unused_iamuser_detail:
            f.writerow([unused_iamuser_detail['ResourceType'], unused_iamuser_detail['ResourceId'], unused_iamuser_detail['Region']])
    unused_resource_count[function] = iamuser_count
def iam_user(function, credentials, unused_resource_count, region_list):
    print('Scanning IAM Users')
    iamuser_count = 0
    unused_iamuser_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'])
        iamuser_data = list(iam.users.all())
        for user in iamuser_data:
            if ((not user.password_last_used) and (not iam_client.list_access_keys(UserName=user.name)['AccessKeyMetadata'])):
                unused_iamuser_detail.append({'ResourceType': 'AWS::IAM::User', 'ResourceId': user.name, 'Region': 'Global'})
                iamuser_count += 1
    except:
        pass
    if iamuser_count:
        unused_iamuser_detail = json.loads(json.dumps(unused_iamuser_detail))
        f = csv.writer(open('./aws_logs/iam_user.csv', 'w', newline=))
        f.writerow(['ResourceType', 'ResourceId', 'Region'])
        for unused_iamuser_detail in unused_iamuser_detail:
            f.writerow([unused_iamuser_detail['ResourceType'], unused_iamuser_detail['ResourceId'], unused_iamuser_detail['Region']])
    unused_resource_count[function] = iamuser_count