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"
"sync"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/state"
@ -113,11 +112,6 @@ func (b *Local) State() (state.State, error) {
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 path := b.StateBackupPath; path != "" {
s = &state.BackupState{

View File

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

View File

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