Merge pull request #7464 from hashicorp/jbardin/GH-7455
core: Return an error when there's no remote state
This commit is contained in:
commit
be2469a05c
|
@ -41,3 +41,21 @@ func testClient(t *testing.T, c Client) {
|
|||
t.Fatalf("bad: %#v", p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteClient_noPayload(t *testing.T) {
|
||||
s := &State{
|
||||
Client: nilClient{},
|
||||
}
|
||||
if err := s.RefreshState(); err != ErrRemoteStateNotFound {
|
||||
t.Fatal("expected ErrRemoteStateNotFound, got", err)
|
||||
}
|
||||
}
|
||||
|
||||
// nilClient returns nil for everything
|
||||
type nilClient struct{}
|
||||
|
||||
func (nilClient) Get() (*Payload, error) { return nil, nil }
|
||||
|
||||
func (c nilClient) Put([]byte) error { return nil }
|
||||
|
||||
func (c nilClient) Delete() error { return nil }
|
||||
|
|
|
@ -2,10 +2,13 @@ package remote
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
var ErrRemoteStateNotFound = errors.New("no remote state found")
|
||||
|
||||
// State implements the State interfaces in the state package to handle
|
||||
// reading and writing the remote state. This State on its own does no
|
||||
// local caching so every persist will go to the remote storage and local
|
||||
|
@ -34,13 +37,14 @@ func (s *State) RefreshState() error {
|
|||
return err
|
||||
}
|
||||
|
||||
var state *terraform.State
|
||||
if payload != nil {
|
||||
state, err = terraform.ReadState(bytes.NewReader(payload.Data))
|
||||
if payload == nil {
|
||||
return ErrRemoteStateNotFound
|
||||
}
|
||||
|
||||
state, err := terraform.ReadState(bytes.NewReader(payload.Data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
s.state = state
|
||||
s.readState = state
|
||||
|
|
Loading…
Reference in New Issue