Merge pull request #29435 from hashicorp/alisdair/fix-add-state-lock

command: Fix stale lock after running add
This commit is contained in:
Alisdair McDiarmid 2021-08-20 15:16:26 -04:00 committed by GitHub
commit dbee7e1492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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")
}
}