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.
This commit is contained in:
parent
c3e943bed2
commit
32ae05c342
|
@ -2,7 +2,7 @@ package remote
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/state"
|
"github.com/hashicorp/terraform/state"
|
||||||
|
@ -35,7 +35,10 @@ func (s *State) WriteState(state *terraform.State) error {
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
if s.readState != nil && !state.SameLineage(s.readState) {
|
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
|
// We create a deep copy of the state here, because the caller also has
|
||||||
|
|
Loading…
Reference in New Issue