|
|
|
|
@ -2,6 +2,7 @@ package command
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
@ -31,14 +32,28 @@ func (c *StatePushCommand) Run(args []string) int {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine our reader for the input state. This is the filepath
|
|
|
|
|
// or stdin if "-" is given.
|
|
|
|
|
var r io.Reader = os.Stdin
|
|
|
|
|
if args[0] != "-" {
|
|
|
|
|
f, err := os.Open(args[0])
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Ui.Error(err.Error())
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Note: we don't need to defer a Close here because we do a close
|
|
|
|
|
// automatically below directly after the read.
|
|
|
|
|
|
|
|
|
|
r = f
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read the state
|
|
|
|
|
f, err := os.Open(args[0])
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Ui.Error(err.Error())
|
|
|
|
|
return 1
|
|
|
|
|
sourceState, err := terraform.ReadState(r)
|
|
|
|
|
if c, ok := r.(io.Closer); ok {
|
|
|
|
|
// Close the reader if possible right now since we're done with it.
|
|
|
|
|
c.Close()
|
|
|
|
|
}
|
|
|
|
|
sourceState, err := terraform.ReadState(f)
|
|
|
|
|
f.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error reading source state %q: %s", args[0], err))
|
|
|
|
|
return 1
|
|
|
|
|
@ -109,6 +124,10 @@ Usage: terraform state push [options] PATH
|
|
|
|
|
This command works with local state (it will overwrite the local
|
|
|
|
|
state), but is less useful for this use case.
|
|
|
|
|
|
|
|
|
|
If PATH is "-", then this command will read the state to push from stdin.
|
|
|
|
|
Data from stdin is not streamed to the backend: it is loaded completely
|
|
|
|
|
(until pipe close), verified, and then pushed.
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
|
|
|
|
|
-force Write the state even if lineages don't match or the
|
|
|
|
|
|