From 32ae05c3427159a9905fcd7851b33856ec98e1db Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 1 Aug 2017 17:51:35 -0400 Subject: [PATCH] fix strict remote.State lineage check We can't check lineage in the remote state instance, because we may need to overwrite a state with a new lineage. Whil it's tempting to add an optional interface for this, like OverwriteState(), optional interfaces are never _really_ optional, and will have to be implemented by any wrapper types as well. Another solution may be to add a State.Supersedes field to indicate that we intend to replace an existing state, but that may not be worth the extra check either. --- state/remote/state.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/state/remote/state.go b/state/remote/state.go index 8e157101d..575e4d187 100644 --- a/state/remote/state.go +++ b/state/remote/state.go @@ -2,7 +2,7 @@ package remote import ( "bytes" - "fmt" + "log" "sync" "github.com/hashicorp/terraform/state" @@ -35,7 +35,10 @@ func (s *State) WriteState(state *terraform.State) error { defer s.mu.Unlock() if s.readState != nil && !state.SameLineage(s.readState) { - return fmt.Errorf("incompatible state lineage; given %s but want %s", state.Lineage, s.readState.Lineage) + // This can't error here, because we need to be able to overwrite the + // state in some cases, like `state push -force` or `workspace new + // -state=` + log.Printf("[WARN] incompatible state lineage; given %s but want %s", state.Lineage, s.readState.Lineage) } // We create a deep copy of the state here, because the caller also has