Prefix is being ignored?

Hey there,

I’m a bit new to Terraform/Terraform Cloud so please bear with me.

In my code I have a backend block defined as such:

terraform {
  backend "remote" {
    organization = "myorg"

    workspaces {
      prefix = "myapp-ecs-"
    }
  }
}

In the documentation I read that while working with workspaces using the CLI, I can use short names that do not include the prefix, but this does not seem to be working.

When I create a new workspace called “dev-us-east-1”, the expected behavior when I do “terraform apply” should be to run in the Terraform Cloud workspace called “myapp-ecs-dev-us-east-1”, but this is not at all what is happening.

Instead, when I create the new workspace “dev-us-east-1”, a workspace named “myorg-dev-us-east-1” is automatically created in Terraform Cloud, and all my runs go to it. It seems my prefix is being completely ignored.

So what am I missing here? :slight_smile:

I typically precreate my workspaces because using terraform workspace new will just initialize it with defaults anyway.

You likely want to tweak some settings or connect vcs in my experience.

The thing is, if I create the workspace in Terraform Cloud, my local shell does not seem to be aware of it at all. When I try to do “terraform workspace select” it says it doesn’t exist.

Solved by adding my organization name to the prefix. Shame this is not mentioned in any documentation :woozy_face:

It should look something like this. I’ve never put the organization name directly in the prefix. perhaps you’re missing the organization block and discovered an alternate way of handling it?

ref: https://www.terraform.io/docs/backends/types/remote.html#basic-configuration

terraform {
  backend "remote" {
    hostname = "app.terraform.io"
    organization = "company"

    workspaces {
      prefix = "my-app-"
    }
  }
}

No, I have the organization in the block. It’s just that whenever I create a new workspace from the CLI, it automatically adds to org name to the beginning of the workspace name in Terraform Cloud.