Documentation ¶
Overview ¶
Package state reads and parses terraform state files.
Index ¶
- Constants
- func WriteState(d *State, dst io.Writer) error
- type EphemeralState
- type InstanceState
- type ModuleState
- type RemoteState
- type ResourceDependency
- type ResourceState
- type ResourceStateV1
- type State
- func (s *State) AddModule(path []string) *ModuleState
- func (s *State) Children(path []string) []*ModuleState
- func (s *State) DeepCopy() *State
- func (s *State) Empty() bool
- func (s *State) Equal(other *State) bool
- func (s *State) GoString() string
- func (s *State) IncrementSerialMaybe(other *State)
- func (s *State) IsRemote() bool
- func (s *State) ModuleByPath(path []string) *ModuleState
- func (s *State) RootModule() *ModuleState
- func (s *State) String() string
- type StateV1
Constants ¶
const ( // StateVersion is the current version for our state file StateVersion = 1 // UnknownVariableValue is a sentinel value that can be used // to denote that the value of a variable is unknown at this time. // RawConfig uses this information to build up data about // unknown keys. UnknownVariableValue = "74D93920-ED26-11E3-AC10-0800200C9A66" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EphemeralState ¶
type EphemeralState struct { // ConnInfo is used for the providers to export information which is // used to connect to the resource for provisioning. For example, // this could contain SSH or WinRM credentials. ConnInfo map[string]string `json:"-"` }
EphemeralState is used for transient state that is only kept in-memory
type InstanceState ¶
type InstanceState struct { // A unique ID for this resource. This is opaque to Terraform // and is only meant as a lookup mechanism for the providers. ID string `json:"id"` // Attributes are basic information about the resource. Any keys here // are accessible in variable format within Terraform configurations: // ${resourcetype.name.attribute}. Attributes map[string]string `json:"attributes,omitempty"` // Ephemeral is used to store any state associated with this instance // that is necessary for the Terraform run to complete, but is not // persisted to a state file. Ephemeral EphemeralState `json:"-"` // Meta is a simple K/V map that is persisted to the State but otherwise // ignored by Terraform core. It's meant to be used for accounting by // external client code. Meta map[string]string `json:"meta,omitempty"` }
InstanceState is used to track the unique state information belonging to a given instance.
func (*InstanceState) Empty ¶
func (s *InstanceState) Empty() bool
func (*InstanceState) Equal ¶
func (s *InstanceState) Equal(other *InstanceState) bool
func (*InstanceState) GoString ¶
func (i *InstanceState) GoString() string
func (*InstanceState) String ¶
func (i *InstanceState) String() string
type ModuleState ¶
type ModuleState struct { // Path is the import path from the root module. Modules imports are // always disjoint, so the path represents amodule tree Path []string `json:"path"` // Outputs declared by the module and maintained for each module // even though only the root module technically needs to be kept. // This allows operators to inspect values at the boundaries. Outputs map[string]string `json:"outputs"` // Resources is a mapping of the logically named resource to // the state of the resource. Each resource may actually have // N instances underneath, although a user only needs to think // about the 1:1 case. Resources map[string]*ResourceState `json:"resources"` // Dependencies are a list of things that this module relies on // existing to remain intact. For example: an module may depend // on a VPC ID given by an aws_vpc resource. // // Terraform uses this information to build valid destruction // orders and to warn the user if they're destroying a module that // another resource depends on. // // Things can be put into this list that may not be managed by // Terraform. If Terraform doesn't find a matching ID in the // overall state, then it assumes it isn't managed and doesn't // worry about it. Dependencies []string `json:"depends_on,omitempty"` }
ModuleState is used to track all the state relevant to a single module. Previous to Terraform 0.3, all state belonged to the "root" module.
func (*ModuleState) Equal ¶
func (m *ModuleState) Equal(other *ModuleState) bool
Equal tests whether one module state is equal to another.
func (*ModuleState) GoString ¶
func (m *ModuleState) GoString() string
func (*ModuleState) IsRoot ¶
func (m *ModuleState) IsRoot() bool
IsRoot says whether or not this module diff is for the root module.
func (*ModuleState) String ¶
func (m *ModuleState) String() string
func (*ModuleState) View ¶
func (m *ModuleState) View(id string) *ModuleState
View returns a view with the given resource prefix.
type RemoteState ¶
type RemoteState struct { // Type controls the client we use for the remote state Type string `json:"type"` // Config is used to store arbitrary configuration that // is type specific Config map[string]string `json:"config"` }
RemoteState is used to track the information about a remote state store that we push/pull state to.
func (*RemoteState) Empty ¶
func (r *RemoteState) Empty() bool
func (*RemoteState) Equals ¶
func (r *RemoteState) Equals(other *RemoteState) bool
func (*RemoteState) GoString ¶
func (r *RemoteState) GoString() string
type ResourceDependency ¶
type ResourceDependency struct { // ID of the resource that we depend on. This ID should map // directly to another ResourceState's ID. ID string }
ResourceDependency maps a resource to another resource that it depends on to remain intact and uncorrupted.
type ResourceState ¶
type ResourceState struct { // This is filled in and managed by Terraform, and is the resource // type itself such as "mycloud_instance". If a resource provider sets // this value, it won't be persisted. Type string `json:"type"` // Dependencies are a list of things that this resource relies on // existing to remain intact. For example: an AWS instance might // depend on a subnet (which itself might depend on a VPC, and so // on). // // Terraform uses this information to build valid destruction // orders and to warn the user if they're destroying a resource that // another resource depends on. // // Things can be put into this list that may not be managed by // Terraform. If Terraform doesn't find a matching ID in the // overall state, then it assumes it isn't managed and doesn't // worry about it. Dependencies []string `json:"depends_on,omitempty"` // Primary is the current active instance for this resource. // It can be replaced but only after a successful creation. // This is the instances on which providers will act. Primary *InstanceState `json:"primary"` // Tainted is used to track any underlying instances that // have been created but are in a bad or unknown state and // need to be cleaned up subsequently. In the // standard case, there is only at most a single instance. // However, in pathological cases, it is possible for the number // of instances to accumulate. Tainted []*InstanceState `json:"tainted,omitempty"` // Deposed is used in the mechanics of CreateBeforeDestroy: the existing // Primary is Deposed to get it out of the way for the replacement Primary to // be created by Apply. If the replacement Primary creates successfully, the // Deposed instance is cleaned up. If there were problems creating the // replacement, the instance remains in the Deposed list so it can be // destroyed in a future run. Functionally, Deposed instances are very // similar to Tainted instances in that Terraform is only tracking them in // order to remember to destroy them. Deposed []*InstanceState `json:"deposed,omitempty"` // Provider is used when a resource is connected to a provider with an alias. // If this string is empty, the resource is connected to the default provider, // e.g. "aws_instance" goes with the "aws" provider. // If the resource block contained a "provider" key, that value will be set here. Provider string `json:"provider,omitempty"` }
ResourceState holds the state of a resource that is used so that a provider can find and manage an existing resource as well as for storing attributes that are used to populate variables of child resources.
Attributes has attributes about the created resource that are queryable in interpolation: "${type.id.attr}"
Extra is just extra data that a provider can return that we store for later, but is not exposed in any way to the user.
func (*ResourceState) Equal ¶
func (s *ResourceState) Equal(other *ResourceState) bool
Equal tests whether two ResourceStates are equal.
func (*ResourceState) GoString ¶
func (s *ResourceState) GoString() string
func (*ResourceState) String ¶
func (s *ResourceState) String() string
func (*ResourceState) Taint ¶
func (r *ResourceState) Taint()
Taint takes the primary state and marks it as tainted. If there is no primary state, this does nothing.
type ResourceStateV1 ¶
type ResourceStateV1 struct { // This is filled in and managed by Terraform, and is the resource // type itself such as "mycloud_instance". If a resource provider sets // this value, it won't be persisted. Type string // A unique ID for this resource. This is opaque to Terraform // and is only meant as a lookup mechanism for the providers. ID string // Attributes are basic information about the resource. Any keys here // are accessible in variable format within Terraform configurations: // ${resourcetype.name.attribute}. Attributes map[string]string // ConnInfo is used for the providers to export information which is // used to connect to the resource for provisioning. For example, // this could contain SSH or WinRM credentials. ConnInfo map[string]string // Extra information that the provider can store about a resource. // This data is opaque, never shown to the user, and is sent back to // the provider as-is for whatever purpose appropriate. Extra map[string]interface{} // Dependencies are a list of things that this resource relies on // existing to remain intact. For example: an AWS instance might // depend on a subnet (which itself might depend on a VPC, and so // on). // // Terraform uses this information to build valid destruction // orders and to warn the user if they're destroying a resource that // another resource depends on. // // Things can be put into this list that may not be managed by // Terraform. If Terraform doesn't find a matching ID in the // overall state, then it assumes it isn't managed and doesn't // worry about it. Dependencies []ResourceDependency }
/ ResourceState holds the state of a resource that is used so that a provider can find and manage an existing resource as well as for storing attributes that are uesd to populate variables of child resources.
Attributes has attributes about the created resource that are queryable in interpolation: "${type.id.attr}"
Extra is just extra data that a provider can return that we store for later, but is not exposed in any way to the user.
func (*ResourceStateV1) GoString ¶
func (s *ResourceStateV1) GoString() string
type State ¶
type State struct { // Version is the protocol version. Currently only "1". Version int `json:"version"` // Serial is incremented on any operation that modifies // the State file. It is used to detect potentially conflicting // updates. Serial int64 `json:"serial"` // Remote is used to track the metadata required to // pull and push state files from a remote storage endpoint. Remote *RemoteState `json:"remote,omitempty"` // Modules contains all the modules in a breadth-first order Modules []*ModuleState `json:"modules"` }
State keeps track of a snapshot state-of-the-world that Terraform can use to keep track of what real world resources it is actually managing. This is the latest format as of Terraform 0.3
func ReadState ¶
ReadState reads a state structure out of a reader in the format that was written by WriteState.
func (*State) AddModule ¶
func (s *State) AddModule(path []string) *ModuleState
AddModule adds the module with the given path to the state.
This should be the preferred method to add module states since it allows us to optimize lookups later as well as control sorting.
func (*State) Children ¶
func (s *State) Children(path []string) []*ModuleState
Children returns the ModuleStates that are direct children of the given path. If the path is "root", for example, then children returned might be "root.child", but not "root.child.grandchild".
func (*State) DeepCopy ¶
DeepCopy performs a deep copy of the state structure and returns a new structure.
func (*State) IncrementSerialMaybe ¶
IncrementSerialMaybe increments the serial number of this state if it different from the other state.
func (*State) IsRemote ¶
IsRemote returns true if State represents a state that exists and is remote.
func (*State) ModuleByPath ¶
func (s *State) ModuleByPath(path []string) *ModuleState
ModuleByPath is used to lookup the module state for the given path. This should be the preferred lookup mechanism as it allows for future lookup optimizations.
func (*State) RootModule ¶
func (s *State) RootModule() *ModuleState
RootModule returns the ModuleState for the root module
type StateV1 ¶
type StateV1 struct { Outputs map[string]string Resources map[string]*ResourceStateV1 Tainted map[string]struct{} // contains filtered or unexported fields }
StateV1 is used to represent the state of Terraform files before 0.3. It is automatically upgraded to a modern State representation on start.
func ReadStateV1 ¶
ReadStateV1 reads a state structure out of a reader in the format that was written by WriteState.