states/statefile: Tolerate nil state in statefile.New

For historical reasons sometimes we have nil state in situations where
we'd still like to persist state snapshots to a store. To make life easier
for those callers, we'll substitute an empty state if we are given a nil
one, thus allowing us to still generate a valid serialization that will
load back in as an empty state.
pull/19086/head
Martin Atkins 8 years ago
parent d93b462e9c
commit 331cb07a05

@ -32,6 +32,13 @@ type File struct {
}
func New(state *states.State, lineage string, serial uint64) *File {
// To make life easier on callers, we'll accept a nil state here and just
// allocate an empty one, which is required for this file to be successfully
// written out.
if state == nil {
state = states.NewState()
}
return &File{
TerraformVersion: tfversion.SemVer,
State: state,

Loading…
Cancel
Save