From 331cb07a05b86ce29ac11a9328e2e2eda5631a5e Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 2 Oct 2018 14:49:45 -0700 Subject: [PATCH] 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. --- states/statefile/file.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/states/statefile/file.go b/states/statefile/file.go index 0694c5cccc..6e20240199 100644 --- a/states/statefile/file.go +++ b/states/statefile/file.go @@ -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,