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

${terraform.workspace} value is default and not actual workspace name (when using the terraform cloud remote backend) #22802

Open
tomerliberman opened this issue Sep 15, 2019 · 7 comments

Comments

@tomerliberman
Copy link

commented Sep 15, 2019

Terraform Version

Terraform v0.12.8

Terraform Configuration Files

resource "aws_instance" "example" {
  count = "${terraform.workspace == "default" ? 5 : 1}"

  # ... other arguments
}

Debug Output

Crash Output

Expected Behavior

Would use actual Cloud Workspace to make the decision

Actual Behavior

terraform.workspace value was "default" and resulted in wrong configuration

Steps to Reproduce

follow this example and use within the cloud offering with a workspace named anything other than default
(https://www.terraform.io/docs/state/workspaces.html#current-workspace-interpolation)

Additional Context

References

@kmoe

This comment has been minimized.

Copy link
Contributor

commented Sep 16, 2019

Thanks for the bug report, @tomerliberman. I've reproduced this issue on Terraform Cloud.

@sandangel

This comment has been minimized.

Copy link

commented Sep 17, 2019

we had to manually change all the terraform.workspace to var.workspace . we just started to have 1 more engineer working on terraform code and we want remote execution to prevent security risk with applying locally. but this bug really a show stopper for us for using terraform cloud.

@tamoanxx

This comment has been minimized.

Copy link

commented Sep 17, 2019

I am having the same issue and can't figure out why this is occuring.

@kmoe Do you have an update as to when this will be corrected?

@tomazberisa

This comment has been minimized.

Copy link

commented Sep 17, 2019

We're seeing the same behavior with v0.11.14

Timeline for a fix would be greatly appreciated.

@hashibot hashibot changed the title ${terraforn.workspace} value is default and not actual workspace name (when using the terraform cloud remote backend) ${terraform.workspace} value is default and not actual workspace name (when using the terraform cloud remote backend) Sep 18, 2019
@unfor19

This comment has been minimized.

Copy link

commented Sep 24, 2019

terraform v0.12.9 - same behavior.

@vliao-semios

This comment has been minimized.

Copy link

commented Sep 30, 2019

One weird thing is when debugging with terraform console, and type terraform.workspace in the interactive console, it shows the actual remote workspace name.

`
$ tf console

terraform.workspace
wonderful_space

`

@saitotqr

This comment has been minimized.

Copy link

commented Oct 3, 2019

Same issue here. I must to add static value for workspaces.name to read backend.
Terraform reads default even if I set workspaces.prefix
It's critical blocker for us for using terraform cloud.

data "terraform_remote_state" "tfcloud" {
  backend = "remote"
  config = {
    organization = "org"
    #static will work, but can't use for another workspace
    #workspaces = {
    #  name = "mywrk-prd"
    #}
    # I want to set like this but doesn't work
    workspaces = {
      prefix = "mywrk-"
    }
  }
}

terraform {
  backend "remote" {
    hostname = "app.terraform.io"
    organization = "org"
    workspaces = {
      prefix = "mywrk-"
    }
  }
}
$ terraform --version
Terraform v0.11.13
+ provider.archive v1.3.0
+ provider.aws v2.30.0
+ provider.template v2.1.2

$ terraform workspace list
* prd

$ terraform plan
...
To view this run in a browser, visit:
https://app.terraform.io/app/mycorp/mywrk/runs/run-xxx

Waiting for the plan to start...

Terraform v0.11.13

Configuring remote state backend...
...

Error: Error refreshing state: 1 error(s) occurred:

* data.terraform_remote_state.tfcloud: 1 error(s) occurred:

* data.terraform_remote_state.tfcloud: data.terraform_remote_state.tfcloud: error loading the remote state: default state not supported
You can create a new workspace with the "workspace new" command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.