backend/local: don't RefreshState on State API

This commit is contained in:
Mitchell Hashimoto 2017-02-22 13:01:16 -08:00
parent 6e1dc9c77d
commit ebb22d3ecd
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 11 additions and 11 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/state" "github.com/hashicorp/terraform/state"
@ -113,11 +112,6 @@ func (b *Local) State() (state.State, error) {
PathOut: b.StateOutPath, PathOut: b.StateOutPath,
} }
// Load the state as a sanity check
if err := s.RefreshState(); err != nil {
return nil, errwrap.Wrapf("Error reading local state: {{err}}", err)
}
// If we are backing up the state, wrap it // If we are backing up the state, wrap it
if path := b.StateBackupPath; path != "" { if path := b.StateBackupPath; path != "" {
s = &state.BackupState{ s = &state.BackupState{

View File

@ -103,6 +103,9 @@ func TestMetaBackend_emptyWithDefaultState(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("bad: %s", err) t.Fatalf("bad: %s", err)
} }
if err := s.RefreshState(); err != nil {
t.Fatalf("err: %s", err)
}
if actual := s.State().String(); actual != testState().String() { if actual := s.State().String(); actual != testState().String() {
t.Fatalf("bad: %s", actual) t.Fatalf("bad: %s", actual)
} }
@ -173,6 +176,9 @@ func TestMetaBackend_emptyWithExplicitState(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("bad: %s", err) t.Fatalf("bad: %s", err)
} }
if err := s.RefreshState(); err != nil {
t.Fatalf("err: %s", err)
}
if actual := s.State().String(); actual != testState().String() { if actual := s.State().String(); actual != testState().String() {
t.Fatalf("bad: %s", actual) t.Fatalf("bad: %s", actual)
} }

View File

@ -45,14 +45,14 @@ func (c *StateMvCommand) Run(args []string) int {
return cli.RunResultHelp return cli.RunResultHelp
} }
stateFromReal := stateFrom.State() if err := stateFrom.RefreshState(); err != nil {
if stateFromReal == nil { c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
c.Ui.Error(fmt.Sprintf(errStateNotFound))
return 1 return 1
} }
if err := stateFrom.RefreshState(); err != nil { stateFromReal := stateFrom.State()
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) if stateFromReal == nil {
c.Ui.Error(fmt.Sprintf(errStateNotFound))
return 1 return 1
} }