github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/states/statefile/file.go (about)

     1  package statefile
     2  
     3  import (
     4  	version "github.com/hashicorp/go-version"
     5  
     6  	"github.com/hashicorp/terraform/internal/states"
     7  	tfversion "github.com/hashicorp/terraform/version"
     8  )
     9  
    10  // File is the in-memory representation of a state file. It includes the state
    11  // itself along with various metadata used to track changing state files for
    12  // the same configuration over time.
    13  type File struct {
    14  	// TerraformVersion is the version of Terraform that wrote this state file.
    15  	TerraformVersion *version.Version
    16  
    17  	// Serial is incremented on any operation that modifies
    18  	// the State file. It is used to detect potentially conflicting
    19  	// updates.
    20  	Serial uint64
    21  
    22  	// Lineage is set when a new, blank state file is created and then
    23  	// never updated. This allows us to determine whether the serials
    24  	// of two states can be meaningfully compared.
    25  	// Apart from the guarantee that collisions between two lineages
    26  	// are very unlikely, this value is opaque and external callers
    27  	// should only compare lineage strings byte-for-byte for equality.
    28  	Lineage string
    29  
    30  	// State is the actual state represented by this file.
    31  	State *states.State
    32  }
    33  
    34  func New(state *states.State, lineage string, serial uint64) *File {
    35  	// To make life easier on callers, we'll accept a nil state here and just
    36  	// allocate an empty one, which is required for this file to be successfully
    37  	// written out.
    38  	if state == nil {
    39  		state = states.NewState()
    40  	}
    41  
    42  	return &File{
    43  		TerraformVersion: tfversion.SemVer,
    44  		State:            state,
    45  		Lineage:          lineage,
    46  		Serial:           serial,
    47  	}
    48  }
    49  
    50  // DeepCopy is a convenience method to create a new File object whose state
    51  // is a deep copy of the receiver's, as implemented by states.State.DeepCopy.
    52  func (f *File) DeepCopy() *File {
    53  	if f == nil {
    54  		return nil
    55  	}
    56  	return &File{
    57  		TerraformVersion: f.TerraformVersion,
    58  		Serial:           f.Serial,
    59  		Lineage:          f.Lineage,
    60  		State:            f.State.DeepCopy(),
    61  	}
    62  }