Loading...
Loading...
### Terraform Version ```shell 1.2.* 1.3.7 1.3.8 1.3.9 1.4.0 ``` ### Terraform Configuration Files providers: ```terraform terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 4.0" } random = { source = "hashicorp/random" version = "~> 3.4.3" } template = { source = "hashicorp/template" version = "~> 2.2.0" } } required_version = "~> 1.3.0" } ``` backend: ```terraform terraform { backend "s3" { bucket = "terraform-state-1234" role_arn = "arn:aws:iam::1111111111111111:role/state-role" key = "terraform.tfstate" workspace_key_prefix = "env" region = "eu-central-1" dynamodb_table = "terraform-state-lock" } } ``` ### Debug Output https://gist.github.com/yyarmoshyk/b17cdb4b25696cd4317805c3aa5e55fc ### Expected Behavior new workspace created ### Actual Behavior The currently selected workspace (test) does not exist. This is expected behavior when the selected workspace did not have an existing non-empty state. Please enter a number to select a workspace: 1. default 2. dev ### Steps to Reproduce 1. ```export TF_WORKSPACE=dev``` 2. ```terraform init``` 3. ```export TF_WORKSPACE=test``` 4. ```terraform init``` ### Additional Context I have a need to initialise new workspaces automatically by updating the list of environments. So basically I have a need to initialise workspace in pipeline for example for sandbox environment, next run init for dev, next run init for stage and so on. I expect that terraform init will create new workspace if I have TF_WORKSPACE environment variable specified. But this doesn't work. Terraform init successfully creates workspace only in the empty s3 bucket. If terraform detects existing workspaces in the bucket, than it fails with the following error instead of creating the new workspace: `The currently selected workspace (dev) does not exist` The existing workaround seems to be redundant (init terraform with default workspace, new create workspace with `terraform workspace new`, next define `TF_WORKSPACE` environment variable and re-run the `terraform init`) Terraform should create new workspaces on init based on the value of TF_WORKSPACE ### References _No response_
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.