mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-18 20:52:58 -06:00
a3403f2766
Due to how often the state and plan types are referenced throughout Terraform, there isn't a great way to switch them out gradually. As a consequence, this huge commit gets us from the old world to a _compilable_ new world, but still has a large number of known test failures due to key functionality being stubbed out. The stubs here are for anything that interacts with providers, since we now need to do the follow-up work to similarly replace the old terraform.ResourceProvider interface with its replacement in the new "providers" package. That work, along with work to fix the remaining failing tests, will follow in subsequent commits. The aim here was to replace all references to terraform.State and its downstream types with states.State, terraform.Plan with plans.Plan, state.State with statemgr.State, and switch to the new implementations of the state and plan file formats. However, due to the number of times those types are used, this also ended up affecting numerous other parts of core such as terraform.Hook, the backend.Backend interface, and most of the CLI commands. Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize in advance to the person who inevitably just found this huge commit while spelunking through the commit history.
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package statefile
|
|
|
|
import (
|
|
version "github.com/hashicorp/go-version"
|
|
|
|
"github.com/hashicorp/terraform/states"
|
|
tfversion "github.com/hashicorp/terraform/version"
|
|
)
|
|
|
|
// File is the in-memory representation of a state file. It includes the state
|
|
// itself along with various metadata used to track changing state files for
|
|
// the same configuration over time.
|
|
type File struct {
|
|
// TerraformVersion is the version of Terraform that wrote this state file.
|
|
TerraformVersion *version.Version
|
|
|
|
// Serial is incremented on any operation that modifies
|
|
// the State file. It is used to detect potentially conflicting
|
|
// updates.
|
|
Serial uint64
|
|
|
|
// Lineage is set when a new, blank state file is created and then
|
|
// never updated. This allows us to determine whether the serials
|
|
// of two states can be meaningfully compared.
|
|
// Apart from the guarantee that collisions between two lineages
|
|
// are very unlikely, this value is opaque and external callers
|
|
// should only compare lineage strings byte-for-byte for equality.
|
|
Lineage string
|
|
|
|
// State is the actual state represented by this file.
|
|
State *states.State
|
|
}
|
|
|
|
func New(state *states.State, lineage string, serial uint64) *File {
|
|
return &File{
|
|
TerraformVersion: tfversion.SemVer,
|
|
State: state,
|
|
Lineage: lineage,
|
|
Serial: serial,
|
|
}
|
|
}
|
|
|
|
// DeepCopy is a convenience method to create a new File object whose state
|
|
// is a deep copy of the receiver's, as implemented by states.State.DeepCopy.
|
|
func (f *File) DeepCopy() *File {
|
|
if f == nil {
|
|
return nil
|
|
}
|
|
return &File{
|
|
TerraformVersion: f.TerraformVersion,
|
|
Serial: f.Serial,
|
|
Lineage: f.Lineage,
|
|
State: f.State.DeepCopy(),
|
|
}
|
|
}
|