Regression: terraform init
can no longer migrate state local to remote, unless versions precisely match - Remote workspace Terraform version "X" does not match local Terraform version "Y"
#29789
Labels
backend/remote
bug
confirmed
a Terraform Core team member has reproduced this issue
v1.0
Issues (primarily bugs) reported against v1.0 releases
Use of
terraform init
to move state between backends is an advanced feature, but vital in some maintenance scenarios. Unfortunately this has regressed in Terraform 0.15 and later.Using
terraform init
to migrate state from a local backend to a remote one mostly no longer works, because it uses the fallback version checking atterraform/internal/backend/remote/backend.go
Lines 638 to 650 in 0fcb750
Terraform Version
Found in Terraform 1.0.9, but I think all versions containing the code from #26947, i.e. 0.15 and later.
Steps to Reproduce
To reproduce, you need:
null_resource
would doremote
backendterraform { backend "remote" { ... } }
block in your configuration soterraform init
knows which TFE/TFC to talk toterraform login
) to the TFE/TFCterraform init
(this sets up the remote backend defined in configuration)terraform { backend "remote" { ... } }
block from your configuration - the default local backend now appliesterraform init -migrate-state -force-copy
to fetch the state from the remote backend and save it locallyterraform { backend "remote" { ... } }
pointing at the remote backendterraform init -migrate-state -force-copy
Expected Behavior
Step 6 above migrates local state to the remote backend
Actual Behavior
Step 6 fails:
Additional Context - Problem is worse in TFE environment
In the above report, I have reproduced the problem using TFC. With TFC, the relatively simple workaround of "Just use the exactly matching Terraform CLI version that the workspace is configured to use" exists.
However, I actually discovered this at work, with our TFE environment, where the issue is much more blocking: in our TFE environment, workspace Terraform version strings don't exactly match any Terraform CLI version, because they identify a bundle containing the Terraform CLI and providers - and so include extra detail identifying the providers they contain. Therefore, the workaround of using a Terraform CLI version that exactly matches the workspace version is impossible, as no such version exists.
Additional Bug -
-ignore-remote-version
option does not work to bypass this errorThe
-ignore-remote-version
option is supposed to bypass checks like this. However, whilst it is applied to a remote backend during normal operation, the Terraform CLI fails to apply the option value to a remote backend being used in a state migration operation.The text was updated successfully, but these errors were encountered: