Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'workspaces not supported' error #148

Open
grzleadams opened this issue Mar 30, 2021 · 10 comments
Open

'workspaces not supported' error #148

grzleadams opened this issue Mar 30, 2021 · 10 comments

Comments

@grzleadams
Copy link

I use an Artifactory backend and when I specify source.env_name or put.params.env_name, I get a workspaces not supported error (which might be fine, because they're not for that backend). But I can't leave them (or the other two options) out because one of the four is required. Using 'default' (which I've seen suggested elsewhere) doesn't seem to help either.

Sanitized backend resource:

  - name: terraform
    type: terraform
    source:
      env_name: default
      env:
        TF_LOG: TRACE
      backend_type: artifactory
      backend_config:
        username: ((artifactory-user))
        password: ((artifactory-token))
        url: ((artifactory-url))
        repo: "terraform-local"
        subpath: "production"

Thanks for any input you can provide!

@ljfranklin
Copy link
Owner

Huh, didn't realize some backends don't support workspaces. Looks like you already have debug logging on, which Terraform command is actually failing? I'm guessing terraform workspaces list but please confirm. If that is the issue you can try adding a line here to return []string{"default"} rather than an error if the output contains workspaces not supported. Instructions to build your own image to test your changes are here.

@grzleadams
Copy link
Author

Yeah, it's terraform workspaces list that's failing. I ended up switching to a pg backend for the sake of progress but am now encountering a whole other set of issues with resource imports in my plan, so it might be a bit before I get to test that solution out. We can close this if you want, or keep it open until I'm able to verify that it works, whatever you want to do.

@laurenty
Copy link

Having the same issue when trying to use Terraform Cloud for backend

@ljfranklin
Copy link
Owner

Looks like the Terraform remote (Cloud) backend does support workspaces, but it returns "not supported" if the prefix key is not provided. @laurenty can you try adding the workspaces.prefix key to your backend_config?

@laurenty
Copy link

@ljfranklin It didn't work. I already had a name configured for the workspace, so adding prefix resulted in the following error.

2021/08/23 01:07:59 terraform init command failed.
Error: exit status 1
Output: 
Initializing the backend...

Error: Invalid workspaces configuration

  on resource_backend_override.tf line 2, in terraform:
   2: 		backend "remote" {}

Only one of workspace "name" or "prefix" is allowed.

Here's the basic config I've been using for testing

---
resource_types:
- name: terraform
  type: docker-image
  source:
    repository: ljfranklin/terraform-resource
    tag: 0.13.5

resources:
- name: source-repo
  type: git
  icon: github
  source:
    uri: https://github.com/<some test repo>.git
    branch: main
  check_every: 1h

- name: core-terraform
  type: terraform
  icon: terraform
  source:
    env_name: test
    backend_type: remote
    backend_config:
      hostname: app.terraform.io
      organization: <org-name>
      token: <token>
      workspaces:
        prefix: dev
        name: concourse-test

jobs:
- name: apply-terraform
  plan:
  - get: source-repo
    trigger: true
  - put: core-terraform
    params:
      plan_only: true
      terraform_source: source-repo

I know that both TF and TFC have workspaces, but they are slightly different concepts.
Per their docs (https://www.terraform.io/docs/cloud/workspaces/index.html)

Note: Terraform Cloud and Terraform CLI both have features called "workspaces," but they're slightly different. CLI workspaces are alternate state files in the same working directory; they're a convenience feature for using one configuration to manage multiple similar groups of resources.

@ljfranklin
Copy link
Owner

Terraform Cloud and Terraform CLI both have features called "workspaces," but they're slightly different

Right, but the Terraform Cloud backend does support the CLI concept of workspaces, i.e. store the statefile remotely.

It should work if you drop workspaces.name and change source.env_name: test to source.env_name: concourse-test. Under the hood the terraform-resource uses the env_name to do operations like terraform workspace select $env_name. If this is a new environment you should be fine, but if concourse-test already exists you'll have to migrate its statefile under the dev prefix.

@laurenty
Copy link

Hi @ljfranklin ,
That did not work either. This is the error I got this time:

2021/08/23 15:39:45 terraform init command failed.
Error: exit status 1
Output: 
Initializing the backend...

Successfully configured the backend "remote"! Terraform will automatically
use this backend unless the backend configuration changes.

Error: No existing workspaces.

Use the "terraform workspace" command to create and select a new workspace.
If the backend already contains existing workspaces, you may need to update
the backend configuration.

Pipeline was:

resources:
- name: source-repo
  type: git
  icon: github
  source:
    uri: https://github.com/<some-repo>.git
    branch: main
  check_every: 1h

- name: core-terraform
  type: terraform
  icon: terraform
  source:
    env_name: concourse-test
    backend_type: remote
    backend_config:
      hostname: app.terraform.io
      organization: <org-name>
      token: <token>
      workspaces:
        prefix: dev

jobs:
- name: apply-terraform
  plan:
  - get: source-repo
    trigger: true
  - put: core-terraform
    params:
      plan_only: true
      terraform_source: source-repo

Looking at the files generated on the container for the put step I see that resource_backend_config.json contains the following:

{"hostname":"app.terraform.io","organization":"<org-name>","token":"<token>","workspaces":{"prefix":"dev"}}

and resource_backend_override.tf:

terraform {
	backend "remote" {}
}

which might explain why it's throwing an error. I'll dig in the code and will let you know what I find.

@gaelL
Copy link

gaelL commented Dec 17, 2021

Hi, is there any plan to support backends that do not provide workspaces ?

I'm encountering the same issue Error running workspace list : exit status 1, Output: workspaces not supported using a Terraform HTTP backend

https://www.terraform.io/language/settings/backends/http

It seems there are more and more platforms offering Terraform HTTP backends. It would be great to have it supported into this Concourse resource.

@ljfranklin
Copy link
Owner

There's an open issue on Terraform to support workspaces in the HTTP backend: hashicorp/terraform#26797. There's also two open draft PRs to add that functionality although they haven't been updated in a while. Trying to work around this limitation in the resource doesn't feel like the right technical solution. I'd rather folks either contribute effort towards getting the HTTP workspace support merged or use a more well-maintained backend type other than HTTP.

@Seraf
Copy link
Contributor

Seraf commented Dec 20, 2021

Hello @ljfranklin :)

The problem is that right now, it makes the resource unusable with Gitlab/Artifaktory/whoever Terraform Backend or all others services that implemented the Terraform Backend according to the specs available in Terraform documentation.

I agree that would be really better for hashicorp to handle it, but that also means we could wait for years to have that supported :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants