aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/terraform/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/state.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/terraform/state.go66
1 files changed, 42 insertions, 24 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/state.go b/vendor/github.com/hashicorp/terraform/terraform/state.go
index 074b682..0c46194 100644
--- a/vendor/github.com/hashicorp/terraform/terraform/state.go
+++ b/vendor/github.com/hashicorp/terraform/terraform/state.go
@@ -533,6 +533,43 @@ func (s *State) equal(other *State) bool {
533 return true 533 return true
534} 534}
535 535
536// MarshalEqual is similar to Equal but provides a stronger definition of
537// "equal", where two states are equal if and only if their serialized form
538// is byte-for-byte identical.
539//
540// This is primarily useful for callers that are trying to save snapshots
541// of state to persistent storage, allowing them to detect when a new
542// snapshot must be taken.
543//
544// Note that the serial number and lineage are included in the serialized form,
545// so it's the caller's responsibility to properly manage these attributes
546// so that this method is only called on two states that have the same
547// serial and lineage, unless detecting such differences is desired.
548func (s *State) MarshalEqual(other *State) bool {
549 if s == nil && other == nil {
550 return true
551 } else if s == nil || other == nil {
552 return false
553 }
554
555 recvBuf := &bytes.Buffer{}
556 otherBuf := &bytes.Buffer{}
557
558 err := WriteState(s, recvBuf)
559 if err != nil {
560 // should never happen, since we're writing to a buffer
561 panic(err)
562 }
563
564 err = WriteState(other, otherBuf)
565 if err != nil {
566 // should never happen, since we're writing to a buffer
567 panic(err)
568 }
569
570 return bytes.Equal(recvBuf.Bytes(), otherBuf.Bytes())
571}
572
536type StateAgeComparison int 573type StateAgeComparison int
537 574
538const ( 575const (
@@ -603,6 +640,10 @@ func (s *State) SameLineage(other *State) bool {
603// DeepCopy performs a deep copy of the state structure and returns 640// DeepCopy performs a deep copy of the state structure and returns
604// a new structure. 641// a new structure.
605func (s *State) DeepCopy() *State { 642func (s *State) DeepCopy() *State {
643 if s == nil {
644 return nil
645 }
646
606 copy, err := copystructure.Config{Lock: true}.Copy(s) 647 copy, err := copystructure.Config{Lock: true}.Copy(s)
607 if err != nil { 648 if err != nil {
608 panic(err) 649 panic(err)
@@ -611,30 +652,6 @@ func (s *State) DeepCopy() *State {
611 return copy.(*State) 652 return copy.(*State)
612} 653}
613 654
614// IncrementSerialMaybe increments the serial number of this state
615// if it different from the other state.
616func (s *State) IncrementSerialMaybe(other *State) {
617 if s == nil {
618 return
619 }
620 if other == nil {
621 return
622 }
623 s.Lock()
624 defer s.Unlock()
625
626 if s.Serial > other.Serial {
627 return
628 }
629 if other.TFVersion != s.TFVersion || !s.equal(other) {
630 if other.Serial > s.Serial {
631 s.Serial = other.Serial
632 }
633
634 s.Serial++
635 }
636}
637
638// FromFutureTerraform checks if this state was written by a Terraform 655// FromFutureTerraform checks if this state was written by a Terraform
639// version from the future. 656// version from the future.
640func (s *State) FromFutureTerraform() bool { 657func (s *State) FromFutureTerraform() bool {
@@ -660,6 +677,7 @@ func (s *State) init() {
660 if s.Version == 0 { 677 if s.Version == 0 {
661 s.Version = StateVersion 678 s.Version = StateVersion
662 } 679 }
680
663 if s.moduleByPath(rootModulePath) == nil { 681 if s.moduleByPath(rootModulePath) == nil {
664 s.addModule(rootModulePath) 682 s.addModule(rootModulePath)
665 } 683 }