Skip to content

TF_WORKSPACE allows workspace names 'terraform workspace' does not #24564

@whatsfordinner

Description

@whatsfordinner

Terraform Version

Terraform v0.12.24

Terraform Configuration Files

Just using a basic S3 backend

terraform {
  backend "s3" {
    key = "github-actions-tfstate"
  }
}

Expected Behavior

Workspace names sourced from TF_WORKSPACE should undergo the same syntax checking as the terraform workspace commands and Terraform should error out appropriately.

Actual Behavior

Using TF_WORKSPACE makes it possible to define invalid workspace names.

Steps to Reproduce

  1. terraform init
  2. terraform workspace new 'inv${}alid'
  3. TF_WORKSPACE='inv${}alid' terraform plan
  4. terraform workspace list

E.g.:

$ terraform init -backend-config="bucket=${STATE_BUCKET}"
$ terraform workspace new 'inv${}alid'
The workspace name "inv${}alid" is not allowed. The name must contain only URL safe
characters, and no path separators.
$ TF_WORKSPACE='inv${}alid' terraform plan
$ terraform workspace list
* default
  inv${}alid
$ terraform workspace select 'inv${}alid'
The workspace name "inv${}alid" is not allowed. The name must contain only URL safe
characters, and no path separators.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconfirmeda Terraform Core team member has reproduced this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions