-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* backend/local: push responsibility for unlocking state into individ…
…ual operations * unlock the state if Context() has an error, exactly as backend/remote does today * terraform console and terraform import will exit before unlocking state in case of error in Context() * responsibility for unlocking state in the local backend is pushed down the stack, out of backend.go and into each individual state operation * add tests confirming that state is not locked after apply and plan * backend/local: add checks that the state is unlocked after operations This adds tests to plan, apply and refresh which validate that the state is unlocked after all operations, regardless of exit status. I've also added specific tests that force Context() to fail during each operation to verify that locking behavior specifically.
- Loading branch information
1 parent
50b2f0f
commit 86e9ba3
Showing
16 changed files
with
247 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package local | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/backend" | ||
"github.com/hashicorp/terraform/internal/initwd" | ||
) | ||
|
||
func TestLocalContext(t *testing.T) { | ||
configDir := "./testdata/empty" | ||
b, cleanup := TestLocal(t) | ||
defer cleanup() | ||
|
||
_, configLoader, configCleanup := initwd.MustLoadConfigForTests(t, configDir) | ||
defer configCleanup() | ||
|
||
op := &backend.Operation{ | ||
ConfigDir: configDir, | ||
ConfigLoader: configLoader, | ||
Workspace: backend.DefaultStateName, | ||
LockState: true, | ||
} | ||
|
||
_, _, diags := b.Context(op) | ||
if diags.HasErrors() { | ||
t.Fatalf("unexpected error: %s", diags.Err().Error()) | ||
} | ||
|
||
// Context() retains a lock on success | ||
assertBackendStateLocked(t, b) | ||
} | ||
|
||
func TestLocalContext_error(t *testing.T) { | ||
configDir := "./testdata/apply" | ||
b, cleanup := TestLocal(t) | ||
defer cleanup() | ||
|
||
_, configLoader, configCleanup := initwd.MustLoadConfigForTests(t, configDir) | ||
defer configCleanup() | ||
|
||
op := &backend.Operation{ | ||
ConfigDir: configDir, | ||
ConfigLoader: configLoader, | ||
Workspace: backend.DefaultStateName, | ||
LockState: true, | ||
} | ||
|
||
_, _, diags := b.Context(op) | ||
if !diags.HasErrors() { | ||
t.Fatal("unexpected success") | ||
} | ||
|
||
// Context() unlocks the state on failure | ||
assertBackendStateUnlocked(t, b) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.