mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Ignore version conflicts when unlocking state (#1123)
Signed-off-by: Joshua Shanks <jjshanks@gmail.com> Signed-off-by: Kuba Martin <kubam@spacelift.io> Co-authored-by: Kuba Martin <kubam@spacelift.io>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
version "github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/terraform-svchost/disco"
|
||||
"github.com/opentofu/opentofu/internal/backend"
|
||||
"github.com/opentofu/opentofu/internal/states/statemgr"
|
||||
"github.com/opentofu/opentofu/internal/tfdiags"
|
||||
tfversion "github.com/opentofu/opentofu/version"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
@@ -530,6 +531,46 @@ func TestRemote_StateMgr_versionCheck(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemote_Unlock_ignoreVersion(t *testing.T) {
|
||||
b, bCleanup := testBackendDefault(t)
|
||||
defer bCleanup()
|
||||
|
||||
// this is set by the unlock command
|
||||
b.IgnoreVersionConflict()
|
||||
|
||||
v111 := version.Must(version.NewSemver("1.1.1"))
|
||||
|
||||
// Save original local version state and restore afterwards
|
||||
p := tfversion.Prerelease
|
||||
v := tfversion.Version
|
||||
s := tfversion.SemVer
|
||||
defer func() {
|
||||
tfversion.Prerelease = p
|
||||
tfversion.Version = v
|
||||
tfversion.SemVer = s
|
||||
}()
|
||||
|
||||
// For this test, the local Terraform version is set to 1.1.1
|
||||
tfversion.Prerelease = ""
|
||||
tfversion.Version = v111.String()
|
||||
tfversion.SemVer = v111
|
||||
|
||||
state, err := b.StateMgr(backend.DefaultStateName)
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
|
||||
lockID, err := state.Lock(statemgr.NewLockInfo())
|
||||
if err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
|
||||
// this should succeed since the version conflict is ignored
|
||||
if err = state.Unlock(lockID); err != nil {
|
||||
t.Fatalf("error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemote_StateMgr_versionCheckLatest(t *testing.T) {
|
||||
b, bCleanup := testBackendDefault(t)
|
||||
defer bCleanup()
|
||||
|
||||
Reference in New Issue
Block a user