Loading...
Loading...
### Terraform Version ```shell 1.11.4 ``` ### Terraform Configuration Files ### `management` Workspace I'm managing the Terraform workspace itself using Terraform in another workspace: ```terraform resource tfe_workspace aws { name = "my-workspace-name" # ... (irrelevant) terraform_version = "~>1.11" } ``` ### `my-workspace-name` Workspace Initially the backend is local: ```terraform terraform { backend local {} } ``` Then I migrate to Terraform Cloud: ```terraform terraform { backend remote { hostname = "app.terraform.io" organization = "myorg" workspaces { name = "my-workspace-name" } } } ``` Within this workspace, I am also defining the same Terraform version constraint: ```terraform terraform { required_version = "~>1.11" } ``` ### Debug Output I am running `terraform init -migrate-state` within `my-workspace-name` after updating the backend, and I am unable to migrate due to the following error: ``` Initializing the backend... Terraform detected that the backend type changed from "local" to "remote". Initializing modules... ╷ │ Error: Error looking up workspace │ │ Invalid Terraform version: Malformed version: ~> 1.11 ╵ ``` ### Expected Behavior I'd expect to be able to migrate the workspace without any issues. ### Actual Behavior The failure message above appears and I am unable to migrate my workspace. The resolution to this issue that I found was: 1. Set `terraform_version = "1.11.4"` (i.e. remove fuzzy matching on Terraform version) on the `tfe_workspace` resource. 2. Apply to update the `tfe_workspace`. 3. Change the backend to remote in the `my-workspace-name` workspace. 4. Perform the migration using `terraform init -migrate-state`. 5. Observe that the migration works. 6. Change the `terraform_version` on the `tfe_workspace` back to `~>1.11` after migration. 7. Run a plan/apply in `my-workspace-name` and observe that it does successfully find the Terraform version successfully. The bug appears to be this: **specifying a fuzzy version of `terraform_version` within a `tfe_workspace` during migration fails; during migration you must set it to a specific actual version, after migration you can revert back to a fuzzy version.** ### Steps to Reproduce 1. Create a workspace we'll call `management`. 2. Declare a `tfe_workspace` named `my-workspace-name` with `terraform_version` set to a non-constant Terraform version, e.g. `~>1.11`. 3. Create a workspace directory `my-workspace-name`, add some resources to it, apply it so we have a statefile to migrate. Set Terraform backend at this point to local. 4. Update the backend definition of `my-workspace-name` to be remote to Terraform Cloud. 5. Attempt `terraform init -migrate-state` for `my-workspace-name`. 6. Observe that it fails to migrate the state due to `Invalid Terraform version: Malformed version: ~> 1.11`. ### Additional Context I'm using Terraform Cloud (whatever the latest is at time of writing) and Terraform `1.11.4` which is the latest version of Terraform. **I'm not reporting this as a bug in the TFE provider because this occurs during `terraform init -migrate-state`, not during any activity of the TFE provider.** ### References _No response_ ### Generative AI / LLM assisted development? _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.