github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/legacy/terraform/state_v1.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package terraform 5 6 // stateV1 keeps track of a snapshot state-of-the-world that Terraform 7 // can use to keep track of what real world resources it is actually 8 // managing. 9 // 10 // stateV1 is _only used for the purposes of backwards compatibility 11 // and is no longer used in Terraform. 12 // 13 // For the upgrade process, see state_upgrade_v1_to_v2.go 14 type stateV1 struct { 15 // Version is the protocol version. "1" for a StateV1. 16 Version int `json:"version"` 17 18 // Serial is incremented on any operation that modifies 19 // the State file. It is used to detect potentially conflicting 20 // updates. 21 Serial int64 `json:"serial"` 22 23 // Remote is used to track the metadata required to 24 // pull and push state files from a remote storage endpoint. 25 Remote *remoteStateV1 `json:"remote,omitempty"` 26 27 // Modules contains all the modules in a breadth-first order 28 Modules []*moduleStateV1 `json:"modules"` 29 } 30 31 type remoteStateV1 struct { 32 // Type controls the client we use for the remote state 33 Type string `json:"type"` 34 35 // Config is used to store arbitrary configuration that 36 // is type specific 37 Config map[string]string `json:"config"` 38 } 39 40 type moduleStateV1 struct { 41 // Path is the import path from the root module. Modules imports are 42 // always disjoint, so the path represents amodule tree 43 Path []string `json:"path"` 44 45 // Outputs declared by the module and maintained for each module 46 // even though only the root module technically needs to be kept. 47 // This allows operators to inspect values at the boundaries. 48 Outputs map[string]string `json:"outputs"` 49 50 // Resources is a mapping of the logically named resource to 51 // the state of the resource. Each resource may actually have 52 // N instances underneath, although a user only needs to think 53 // about the 1:1 case. 54 Resources map[string]*resourceStateV1 `json:"resources"` 55 56 // Dependencies are a list of things that this module relies on 57 // existing to remain intact. For example: an module may depend 58 // on a VPC ID given by an aws_vpc resource. 59 // 60 // Terraform uses this information to build valid destruction 61 // orders and to warn the user if they're destroying a module that 62 // another resource depends on. 63 // 64 // Things can be put into this list that may not be managed by 65 // Terraform. If Terraform doesn't find a matching ID in the 66 // overall state, then it assumes it isn't managed and doesn't 67 // worry about it. 68 Dependencies []string `json:"depends_on,omitempty"` 69 } 70 71 type resourceStateV1 struct { 72 // This is filled in and managed by Terraform, and is the resource 73 // type itself such as "mycloud_instance". If a resource provider sets 74 // this value, it won't be persisted. 75 Type string `json:"type"` 76 77 // Dependencies are a list of things that this resource relies on 78 // existing to remain intact. For example: an AWS instance might 79 // depend on a subnet (which itself might depend on a VPC, and so 80 // on). 81 // 82 // Terraform uses this information to build valid destruction 83 // orders and to warn the user if they're destroying a resource that 84 // another resource depends on. 85 // 86 // Things can be put into this list that may not be managed by 87 // Terraform. If Terraform doesn't find a matching ID in the 88 // overall state, then it assumes it isn't managed and doesn't 89 // worry about it. 90 Dependencies []string `json:"depends_on,omitempty"` 91 92 // Primary is the current active instance for this resource. 93 // It can be replaced but only after a successful creation. 94 // This is the instances on which providers will act. 95 Primary *instanceStateV1 `json:"primary"` 96 97 // Tainted is used to track any underlying instances that 98 // have been created but are in a bad or unknown state and 99 // need to be cleaned up subsequently. In the 100 // standard case, there is only at most a single instance. 101 // However, in pathological cases, it is possible for the number 102 // of instances to accumulate. 103 Tainted []*instanceStateV1 `json:"tainted,omitempty"` 104 105 // Deposed is used in the mechanics of CreateBeforeDestroy: the existing 106 // Primary is Deposed to get it out of the way for the replacement Primary to 107 // be created by Apply. If the replacement Primary creates successfully, the 108 // Deposed instance is cleaned up. If there were problems creating the 109 // replacement, the instance remains in the Deposed list so it can be 110 // destroyed in a future run. Functionally, Deposed instances are very 111 // similar to Tainted instances in that Terraform is only tracking them in 112 // order to remember to destroy them. 113 Deposed []*instanceStateV1 `json:"deposed,omitempty"` 114 115 // Provider is used when a resource is connected to a provider with an alias. 116 // If this string is empty, the resource is connected to the default provider, 117 // e.g. "aws_instance" goes with the "aws" provider. 118 // If the resource block contained a "provider" key, that value will be set here. 119 Provider string `json:"provider,omitempty"` 120 } 121 122 type instanceStateV1 struct { 123 // A unique ID for this resource. This is opaque to Terraform 124 // and is only meant as a lookup mechanism for the providers. 125 ID string `json:"id"` 126 127 // Attributes are basic information about the resource. Any keys here 128 // are accessible in variable format within Terraform configurations: 129 // ${resourcetype.name.attribute}. 130 Attributes map[string]string `json:"attributes,omitempty"` 131 132 // Ephemeral is used to store any state associated with this instance 133 // that is necessary for the Terraform run to complete, but is not 134 // persisted to a state file. 135 Ephemeral ephemeralStateV1 `json:"-"` 136 137 // Meta is a simple K/V map that is persisted to the State but otherwise 138 // ignored by Terraform core. It's meant to be used for accounting by 139 // external client code. 140 Meta map[string]string `json:"meta,omitempty"` 141 } 142 143 type ephemeralStateV1 struct { 144 // ConnInfo is used for the providers to export information which is 145 // used to connect to the resource for provisioning. For example, 146 // this could contain SSH or WinRM credentials. 147 ConnInfo map[string]string `json:"-"` 148 }