From 7590154974ff52eca3654f8f5ad7bced07de0e5c Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 30 Jan 2017 17:15:45 -0500 Subject: [PATCH] Don't create empty backups Not really a problem, but created unnecessary files and changes existing behavior. --- state/backup.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/state/backup.go b/state/backup.go index fe93fcba04..bb935eb09b 100644 --- a/state/backup.go +++ b/state/backup.go @@ -1,8 +1,6 @@ package state -import ( - "github.com/hashicorp/terraform/terraform" -) +import "github.com/hashicorp/terraform/terraform" // BackupState wraps a State that backs up the state on the first time that // a WriteState or PersistState is called. @@ -68,9 +66,14 @@ func (s *BackupState) backup() error { state = s.Real.State() } - ls := &LocalState{Path: s.Path} - if err := ls.WriteState(state); err != nil { - return err + // LocalState.WriteState ensures that a file always exists for locking + // purposes, but we don't need a backup or lock if the state is empty, so + // skip this with a nil state. + if state != nil { + ls := &LocalState{Path: s.Path} + if err := ls.WriteState(state); err != nil { + return err + } } s.done = true