diff --git a/remote/client.go b/remote/client.go index a0866b4cb..9c7ab2c43 100644 --- a/remote/client.go +++ b/remote/client.go @@ -17,8 +17,8 @@ import ( // RemoteStatePayload is used to return the remote state // along with associated meta data when we do a remote fetch. type RemoteStatePayload struct { - MD5 []byte - R io.Reader + MD5 []byte + State []byte } // GetState is used to read the remote state @@ -72,7 +72,7 @@ func GetState(conf *terraform.RemoteState) (*RemoteStatePayload, error) { // Create the payload payload := &RemoteStatePayload{ - R: buf, + State: buf.Bytes(), } // Check if this is Consul @@ -88,11 +88,7 @@ func GetState(conf *terraform.RemoteState) (*RemoteStatePayload, error) { } // Setup the reader to pull the value from Consul - payload.R = bytes.NewReader(values[0].Value) - - // Generate the MD5 - hash := md5.Sum(values[0].Value) - payload.MD5 = hash[:md5.Size] + payload.State = values[0].Value } } @@ -104,9 +100,9 @@ func GetState(conf *terraform.RemoteState) (*RemoteStatePayload, error) { } payload.MD5 = md5 - } else if _, ok := payload.R.(*bytes.Buffer); ok { + } else { // Generate the MD5 - hash := md5.Sum(buf.Bytes()) + hash := md5.Sum(payload.State) payload.MD5 = hash[:md5.Size] } diff --git a/remote/client_test.go b/remote/client_test.go index fc639a091..9a4d871a1 100644 --- a/remote/client_test.go +++ b/remote/client_test.go @@ -3,7 +3,6 @@ package remote import ( "bytes" "crypto/md5" - "io" "net/http" "net/http/httptest" "strings" @@ -63,9 +62,7 @@ REQ: } // Check the body - var buf bytes.Buffer - io.Copy(&buf, payload.R) - if string(buf.Bytes()) != "testing" { + if string(payload.State) != "testing" { t.Fatalf("Bad body") } @@ -151,9 +148,7 @@ func TestGetState(t *testing.T) { } if tc.Body != nil { - buf := bytes.NewBuffer(nil) - io.Copy(buf, payload.R) - if !bytes.Equal(buf.Bytes(), tc.Body) { + if !bytes.Equal(payload.State, tc.Body) { t.Fatalf("bad: %#v", payload) } }