diff --git a/command/apply.go b/command/apply.go index 941d1db88..7553da047 100644 --- a/command/apply.go +++ b/command/apply.go @@ -82,8 +82,8 @@ func (c *ApplyCommand) Run(args []string) int { log.Printf("[INFO] Writing backup state to: %s", backupPath) f, err := os.Create(backupPath) if err == nil { - defer f.Close() err = terraform.WriteState(c.State, f) + f.Close() } if err != nil { c.Ui.Error(fmt.Sprintf("Error writing backup state file: %s", err)) diff --git a/command/plan.go b/command/plan.go index 32ee31527..67edae234 100644 --- a/command/plan.go +++ b/command/plan.go @@ -80,8 +80,8 @@ func (c *PlanCommand) Run(args []string) int { log.Printf("[INFO] Writing backup state to: %s", backupPath) f, err := os.Create(backupPath) if err == nil { - defer f.Close() err = terraform.WriteState(c.State, f) + f.Close() } if err != nil { c.Ui.Error(fmt.Sprintf("Error writing backup state file: %s", err)) diff --git a/command/refresh.go b/command/refresh.go index f3038f96a..69ff45601 100644 --- a/command/refresh.go +++ b/command/refresh.go @@ -98,8 +98,8 @@ func (c *RefreshCommand) Run(args []string) int { log.Printf("[INFO] Writing backup state to: %s", backupPath) f, err := os.Create(backupPath) if err == nil { - defer f.Close() err = terraform.WriteState(c.State, f) + f.Close() } if err != nil { c.Ui.Error(fmt.Sprintf("Error writing backup state file: %s", err))