github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/states/statemgr/persistent.go (about) 1 package statemgr 2 3 import ( 4 version "github.com/hashicorp/go-version" 5 6 "github.com/hashicorp/terraform/internal/states" 7 "github.com/hashicorp/terraform/internal/terraform" 8 ) 9 10 // Persistent is a union of the Refresher and Persistent interfaces, for types 11 // that deal with persistent snapshots. 12 // 13 // Persistent snapshots are ones that are retained in storage that will 14 // outlive a particular Terraform process, and are shared with other Terraform 15 // processes that have a similarly-configured state manager. 16 // 17 // A manager may also choose to retain historical persistent snapshots, but 18 // that is an implementation detail and not visible via this API. 19 type Persistent interface { 20 Refresher 21 Persister 22 OutputReader 23 } 24 25 // OutputReader is the interface for managers that fetches output values from state 26 // or another source. This is a refinement of fetching the entire state and digging 27 // the output values from it because enhanced backends can apply special permissions 28 // to differentiate reading the state and reading the outputs within the state. 29 type OutputReader interface { 30 // GetRootOutputValues fetches the root module output values from state or another source 31 GetRootOutputValues() (map[string]*states.OutputValue, error) 32 } 33 34 // Refresher is the interface for managers that can read snapshots from 35 // persistent storage. 36 // 37 // Refresher is usually implemented in conjunction with Reader, with 38 // RefreshState copying the latest persistent snapshot into the latest 39 // transient snapshot. 40 // 41 // For a type that implements both Refresher and Persister, RefreshState must 42 // return the result of the most recently completed successful call to 43 // PersistState, unless another concurrently-running process has persisted 44 // another snapshot in the mean time. 45 // 46 // The Refresher implementation must guarantee that the snapshot is read 47 // from persistent storage in a way that is safe under concurrent calls to 48 // PersistState that may be happening in other processes. 49 type Refresher interface { 50 // RefreshState retrieves a snapshot of state from persistent storage, 51 // returning an error if this is not possible. 52 // 53 // Types that implement RefreshState generally also implement a State 54 // method that returns the result of the latest successful refresh. 55 // 56 // Since only a subset of the data in a state is included when persisting, 57 // a round-trip through PersistState and then RefreshState will often 58 // return only a subset of what was written. Callers must assume that 59 // ephemeral portions of the state may be unpopulated after calling 60 // RefreshState. 61 RefreshState() error 62 } 63 64 // Persister is the interface for managers that can write snapshots to 65 // persistent storage. 66 // 67 // Persister is usually implemented in conjunction with Writer, with 68 // PersistState copying the latest transient snapshot to be the new latest 69 // persistent snapshot. 70 // 71 // A Persister implementation must detect updates made by other processes 72 // that may be running concurrently and avoid destroying those changes. This 73 // is most commonly achieved by making use of atomic write capabilities on 74 // the remote storage backend in conjunction with book-keeping with the 75 // Serial and Lineage fields in the standard state file formats. 76 // 77 // Some implementations may optionally utilize config schema to persist 78 // state. For example, when representing state in an external JSON 79 // representation. 80 type Persister interface { 81 PersistState(*terraform.Schemas) error 82 } 83 84 // PersistentMeta is an optional extension to Persistent that allows inspecting 85 // the metadata associated with the snapshot that was most recently either 86 // read by RefreshState or written by PersistState. 87 type PersistentMeta interface { 88 // StateSnapshotMeta returns metadata about the state snapshot most 89 // recently created either by a call to PersistState or read by a call 90 // to RefreshState. 91 // 92 // If no persistent snapshot is yet available in the manager then 93 // the return value is meaningless. This method is primarily available 94 // for testing and logging purposes, and is of little use otherwise. 95 StateSnapshotMeta() SnapshotMeta 96 } 97 98 // SnapshotMeta contains metadata about a persisted state snapshot. 99 // 100 // This metadata is usually (but not necessarily) included as part of the 101 // "header" of a state file, which is then written to a raw blob storage medium 102 // by a persistent state manager. 103 // 104 // Not all state managers will have useful values for all fields in this 105 // struct, so SnapshotMeta values are of little use beyond testing and logging 106 // use-cases. 107 type SnapshotMeta struct { 108 // Lineage and Serial can be used to understand the relationships between 109 // snapshots. 110 // 111 // If two snapshots both have an identical, non-empty Lineage 112 // then the one with the higher Serial is newer than the other. 113 // If the Lineage values are different or empty then the two snapshots 114 // are unrelated and cannot be compared for relative age. 115 Lineage string 116 Serial uint64 117 118 // TerraformVersion is the number of the version of Terraform that created 119 // the snapshot. 120 TerraformVersion *version.Version 121 }