##### SUMMARY
Some terraform backends don't support workspaces. The module should not fail when using them.

The module fails with messages like:
- `Failed to list Terraform workspaces:\r\nworkspaces not supported\n`
- `Failed to list Terraform workspaces:\r\nnamed states not supported\n`

Related to:
- https://github.com/ansible/ansible/issues/43134#issuecomment-480873362
- https://github.com/ansible/ansible/issues/59089
- https://github.com/ansible/ansible/pull/57402

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
terraform module

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible 2.9.0
  config file = /home/$USER/.ansible.cfg
  configured module search path = ['/home/$USER/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.4 (default, Oct  4 2019, 06:57:26) [GCC 9.2.0]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
ANSIBLE_SSH_ARGS(/home/$USER/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s
DEFAULT_HOST_LIST(/home/$USER/.ansible.cfg) = ['/home/$USER/.ansible/hosts']
```

##### OS / ENVIRONMENT
Archlinux up to date.


##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
- Have an artifactory account accessible
- configure terraform with the artifactory backend

```hcl
terraform {
  backend "artifactory" {
    url      = "https://artifactory.example.com/artifactory"
    repo     = "terraform"
    subpath  = "test"
  }
}
```

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: test terraform no workspace
  hosts: localhost

  tasks:

  - name: apply configuration
    terraform:
      project_path: "{{ playbook_dir }}/terraform/"
      force_init: true
      backend_config:
        username: "{{ artifactory_user }}"
        password: "{{ artifactory_password }}"
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
The module should work without workspaces support from terraform. No error message.

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes -->
```paste below
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: $USER
<127.0.0.1> EXEC /bin/sh -c 'echo ~$USER && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/$USER/.ansible/tmp/ansible-tmp-1573660522.1152759-71895853408161 `" && echo ansible-tmp-1573660522.1152759-71895853408161="` echo /home/$USER/.ansible/tmp/ansible-tmp-1573660522.1152759-71895853408161 `" ) && sleep 0'
Using module file /usr/lib/python3.7/site-packages/ansible/modules/cloud/misc/terraform.py
<127.0.0.1> PUT /home/$USER/.ansible/tmp/ansible-local-100380yrb34ja/tmpcdahl6p2 TO /home/$USER/.ansible/tmp/ansible-tmp-1573660522.1152759-71895853408161/AnsiballZ_terraform.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/$USER/.ansible/tmp/ansible-tmp-1573660522.1152759-71895853408161/ /home/$USER/.ansible/tmp/ansible-tmp-1573660522.1152759-71895853408161/AnsiballZ_terraform.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/$USER/.ansible/tmp/ansible-tmp-1573660522.1152759-71895853408161/AnsiballZ_terraform.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/$USER/.ansible/tmp/ansible-tmp-1573660522.1152759-71895853408161/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "backend_config": {
                "password": "XXXXX",
                "username": "XXXXX"
            },
            "binary_path": null,
            "force_init": true,
            "lock": true,
            "lock_timeout": null,
            "plan_file": null,
            "project_path": "XXX",
            "purge_workspace": false,
            "state": "present",
            "state_file": null,
            "targets": [],
            "variables": {},
            "variables_file": null,
            "workspace": "default"
        }
    },
    "msg": "Failed to list Terraform workspaces:\r\nworkspaces not supported\n"
```

##### FIX
A fix was proposed: https://github.com/ansible/ansible/pull/57402

I tried another approach: defaulting to the default workspace when the workspace listing fails:
```diff
diff --git a/lib/ansible/modules/cloud/misc/terraform.py b/lib/ansible/modules/cloud/misc/terraform.py
index 1d54be2f4b..5c9832c8b0 100644
--- a/lib/ansible/modules/cloud/misc/terraform.py
+++ b/lib/ansible/modules/cloud/misc/terraform.py
@@ -208,7 +208,7 @@ def get_workspace_context(bin_path, project_path):
     workspace_ctx = {"current": "default", "all": []}
     command = [bin_path, 'workspace', 'list', '-no-color']
     rc, out, err = module.run_command(command, cwd=project_path)
-    if rc != 0:
+    if rc != 0 and err.strip() != "workspaces not supported":
         module.fail_json(msg="Failed to list Terraform workspaces:\r\n{0}".format(err))
     for item in out.split('\n'):
         stripped_item = item.strip()
```

The test works for the artifactory backend, but I suspect it won't on other backends. The error message `workspaces not supported` seems backend specific.
'-var',
            '{0}={1}'.format(k, v)
        ])
    if variables_file:
        variables_args.extend(['-var-file', variables_file])
    preflight_validation(command[0], project_path, variables_args)
    if module.params.get('lock') is not None:
        if module.params.get('lock'):
            command.append('-lock=true')
        else:
            command.append('-lock=false')
    if module.params.get('lock_timeout') is not None:
        command.append('-lock-timeout=%ds' % module.params.get('lock_timeout'))
    for t in (module.params.get('targets') or []):
        command.extend(['-target', t])
    
    needs_application, changed = True, False
    if state == 'absent':
        command.extend(variables_args)
    elif state == 'present' and plan_file:
        if any([os.path.isfile(project_path + "/" + plan_file), os.path.isfile(plan_file)]):
            command.append(plan_file)
        else:
            module.fail_json(msg='Could not find plan_file "{0}", check the path and try again.'.format(plan_file))
    else:
        plan_file, needs_application, out, err, command = build_plan(command, project_path, variables_args, state_file,
                                                                     module.params.get('targets'), state, plan_file)
        command.append(plan_file)
    out, err = '', ''
    if needs_application and not module.check_mode and not state == 'planned':