github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/states/statemgr/transient.go (about) 1 package statemgr 2 3 import "github.com/hashicorp/terraform/states" 4 5 // Transient is a union of the Reader and Writer interfaces, for types that 6 // deal with transient snapshots. 7 // 8 // Transient snapshots are ones that are generally retained only locally and 9 // to not create any historical version record when updated. Transient 10 // snapshots are not expected to outlive a particular Terraform process, 11 // and are not shared with any other process. 12 // 13 // A state manager type that is primarily concerned with persistent storage 14 // may embed type Transient and then call State from its PersistState and 15 // WriteState from its RefreshState in order to build on any existing 16 // Transient implementation, such as the one returned by NewTransientInMemory. 17 type Transient interface { 18 Reader 19 Writer 20 } 21 22 // Reader is the interface for managers that can return transient snapshots 23 // of state. 24 // 25 // Retrieving the snapshot must not fail, so retrieving a snapshot from remote 26 // storage (for example) should be dealt with elsewhere, often in an 27 // implementation of Refresher. For a type that implements both Reader 28 // and Refresher, it is okay for State to return nil if called before 29 // a RefreshState call has completed. 30 // 31 // For a type that implements both Reader and Writer, State must return the 32 // result of the most recently completed call to WriteState, and the state 33 // manager must accept concurrent calls to both State and WriteState. 34 // 35 // Each caller of this function must get a distinct copy of the state, and 36 // it must also be distinct from any instance cached inside the reader, to 37 // ensure that mutations of the returned state will not affect the values 38 // returned to other callers. 39 type Reader interface { 40 // State returns the latest state. 41 // 42 // Each call to State returns an entirely-distinct copy of the state, with 43 // no storage shared with any other call, so the caller may freely mutate 44 // the returned object via the state APIs. 45 State() *states.State 46 } 47 48 // Writer is the interface for managers that can create transient snapshots 49 // from state. 50 // 51 // Writer is the opposite of Reader, and so it must update whatever the State 52 // method reads from. It does not write the state to any persistent 53 // storage, and (for managers that support historical versions) must not 54 // be recorded as a persistent new version of state. 55 // 56 // Implementations that cache the state in memory must take a deep copy of it, 57 // since the caller may continue to modify the given state object after 58 // WriteState returns. 59 type Writer interface { 60 // Write state saves a transient snapshot of the given state. 61 // 62 // The caller must ensure that the given state object is not concurrently 63 // modified while a WriteState call is in progress. WriteState itself 64 // will never modify the given state. 65 WriteState(*states.State) error 66 }