import re


def terraform_workspace_exists(terraform, workspace):
    """
    Check if a given terraform workspace exists
    """
    return_code, stdout, stderr = terraform.cmd('workspace list')
    workspaces = list(filter(None, [re.sub('[\s+\*]', '', ws) for ws in stdout.split('\n')]))
    return workspace in workspaces