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