Loading...
Loading...
### Terraform Version 1.0.10 and 1.0.11, so far as I tested ### Scenario 1 to reproduce the issue The terraform Configuration Files, with explicit "local" backend config ```terraform resource "null_resource" "test" { triggers = { a = 100 } } terraform { backend "local" { } } ``` ```shell terraform init terraform workspace new myws terraform apply # tfstate is written to file terraform.tfstate.d/myws/terraform.tfstate # one might check in the tfstate file into vcs. # remove dir .terraform/ # the initialized backend state (.terraform/terraform.tfstate) is gone after this step # it is equivalent to someone making a fresh check-out of the source code with tfstate file rm -rf .terraform/ # init, while dir terraform.tfstate.d/ is present, and dir .terraform/ is not terraform init ``` Then you will get the local-to-local migrating prompt as below Initializing the backend... Do you want to migrate all workspaces to "local"? Both the existing "local" backend and the newly configured "local" backend support workspaces. When migrating between backends, Terraform will copy all workspaces (with the same names). THIS WILL OVERWRITE any conflicting states in the destination. Terraform initialization doesn't currently migrate only select workspaces. If you want to migrate a select number of workspaces, you must manually pull and push those states. If you answer "yes", Terraform will migrate all states. If you answer "no", Terraform will abort. Enter a value: ### Scenario 2 to reproduce the issue The terraform configuration files, with no explicit "local" backend config. ```terraform resource "null_resource" "test" { triggers = { a = 100 } } ``` ```shell terraform init # because no explicit backend config, file .terraform/terraform.tfstate wouldn't be created terraform workspace new myws terraform apply # tfstate is written to file terraform.tfstate.d/myws/terraform.tfstate # Now, add the explicit "local" backend config, as below # terraform { # backend "local" { # } # } # Then init again terraform init ``` Then you will get the same local-to-local migrating prompt as shown above. ### Other context - If I make the dir `terraform.state.d` disappear before the second `terraform init`, the issue won't come out. - If the explicit "local" backend config in scenario 1 has such settings `workspace_dir = "whatever"`, the issue won't come out. - If I don't make new terraform workspace, just use the "default" one, the issue won't come out. ### Why I consider it an issue - In my whole example, the explicit "local" backend config has no non-default settings, which means it is the same whether it exists or not, so the migration is not needed at all. - The two scenarios are not the corner cases, especially for the first one, that I think happens in certain workflow. - Let alone that the issue happens only when using non-default workspace with the default workspace dir, which is `terraform.tfstate.d`.
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.