def convert_instance_profile_to_role(arn, iam_client):
    """Convert the arn to an instance profile

    Both role and instance profile arns are accepted
    raises botocore.exceptions.ClientError if there's a problem with the iam_client
    raises ValueError if there's a problem converting the arn to a role
    """
    if ':instance-profile/' in arn:
        name = arn.split(':instance-profile/')[-1]
        return iam_client.get_instance_profile(InstanceProfileName=name)[
            'InstanceProfile']['Roles'][0]['Arn']
    elif ':role/' in arn:
        return arn
    else:
        return ValueError(
            'Arn {} not recognized as either an instance-profile or a role'
            .format(arn))
