command: Fix stale lock after running add
This commit is contained in:
parent
498dc36635
commit
70a4f7a6b6
|
@ -106,6 +106,14 @@ func (c *AddCommand) Run(rawArgs []string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
// Successfully creating the context can result in a lock, so ensure we release it
|
||||
defer func() {
|
||||
diags := opReq.StateLocker.Unlock()
|
||||
if diags.HasErrors() {
|
||||
c.showDiagnostics(diags)
|
||||
}
|
||||
}()
|
||||
|
||||
// load the configuration to verify that the resource address doesn't
|
||||
// already exist in the config.
|
||||
var module *configs.Module
|
||||
|
|
|
@ -3,6 +3,7 @@ package command
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -592,4 +593,7 @@ resource "test_instance" "new" {
|
|||
t.Fatalf("wrong output:\n%s", cmp.Diff(expected, output.Stdout()))
|
||||
}
|
||||
|
||||
if _, err := os.Stat(filepath.Join(td, ".terraform.tfstate.lock.info")); !os.IsNotExist(err) {
|
||||
t.Fatal("state left locked after add")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue