diff --git a/command/apply.go b/command/apply.go index 7553da047..a1453bf99 100644 --- a/command/apply.go +++ b/command/apply.go @@ -78,11 +78,11 @@ func (c *ApplyCommand) Run(args []string) int { } // Create a backup of the state before updating - if backupPath != "-" && c.State != nil { + if backupPath != "-" && c.state != nil { log.Printf("[INFO] Writing backup state to: %s", backupPath) f, err := os.Create(backupPath) if err == nil { - err = terraform.WriteState(c.State, f) + err = terraform.WriteState(c.state, f) f.Close() } if err != nil { diff --git a/command/meta.go b/command/meta.go index 2dda7a974..0867ffdda 100644 --- a/command/meta.go +++ b/command/meta.go @@ -16,7 +16,10 @@ type Meta struct { Color bool ContextOpts *terraform.ContextOpts Ui cli.Ui - State *terraform.State + + // State read when calling `Context`. This is available after calling + // `Context`. + state *terraform.State // This can be set by the command itself to provide extra hooks. extraHooks []terraform.Hook @@ -79,7 +82,7 @@ func (m *Meta) Context(path, statePath string) (*terraform.Context, bool, error) } // Store the loaded state - m.State = state + m.state = state config, err := config.LoadDir(path) if err != nil { @@ -93,7 +96,6 @@ func (m *Meta) Context(path, statePath string) (*terraform.Context, bool, error) opts.State = state ctx := terraform.NewContext(opts) return ctx, false, nil - } // contextOpts returns the options to use to initialize a Terraform diff --git a/command/plan.go b/command/plan.go index 67edae234..322bc6fa4 100644 --- a/command/plan.go +++ b/command/plan.go @@ -76,11 +76,11 @@ func (c *PlanCommand) Run(args []string) int { if refresh { // Create a backup of the state before updating - if backupPath != "-" && c.State != nil { + if backupPath != "-" && c.state != nil { log.Printf("[INFO] Writing backup state to: %s", backupPath) f, err := os.Create(backupPath) if err == nil { - err = terraform.WriteState(c.State, f) + err = terraform.WriteState(c.state, f) f.Close() } if err != nil { diff --git a/command/refresh.go b/command/refresh.go index 69ff45601..1603a75c8 100644 --- a/command/refresh.go +++ b/command/refresh.go @@ -94,11 +94,11 @@ func (c *RefreshCommand) Run(args []string) int { } // Create a backup of the state before updating - if backupPath != "-" && c.State != nil { + if backupPath != "-" && c.state != nil { log.Printf("[INFO] Writing backup state to: %s", backupPath) f, err := os.Create(backupPath) if err == nil { - err = terraform.WriteState(c.State, f) + err = terraform.WriteState(c.state, f) f.Close() } if err != nil {