Don't create empty backups

Not really a problem, but created unnecessary files and changes existing
behavior.
This commit is contained in:
James Bardin 2017-01-30 17:15:45 -05:00
parent 1646310e68
commit 7590154974
1 changed files with 9 additions and 6 deletions

View File

@ -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