6 "github.com/hashicorp/terraform/addrs"
7 "github.com/hashicorp/terraform/states"
8 "github.com/zclconf/go-cty/cty"
11 // ResourceInstanceChangeSrc is a not-yet-decoded ResourceInstanceChange.
12 // Pass the associated resource type's schema type to method Decode to
13 // obtain a ResourceInstancChange.
14 type ResourceInstanceChangeSrc struct {
15 // Addr is the absolute address of the resource instance that the change
17 Addr addrs.AbsResourceInstance
19 // DeposedKey is the identifier for a deposed object associated with the
20 // given instance, or states.NotDeposed if this change applies to the
23 // A Replace change for a resource with create_before_destroy set will
24 // create a new DeposedKey temporarily during replacement. In that case,
25 // DeposedKey in the plan is always states.NotDeposed, representing that
26 // the current object is being replaced with the deposed.
27 DeposedKey states.DeposedKey
29 // Provider is the address of the provider configuration that was used
30 // to plan this change, and thus the configuration that must also be
32 ProviderAddr addrs.AbsProviderConfig
34 // ChangeSrc is an embedded description of the not-yet-decoded change.
37 // RequiredReplace is a set of paths that caused the change action to be
38 // Replace rather than Update. Always nil if the change action is not
41 // This is retained only for UI-plan-rendering purposes and so it does not
42 // currently survive a round-trip through a saved plan file.
43 RequiredReplace cty.PathSet
45 // Private allows a provider to stash any extra data that is opaque to
46 // Terraform that relates to this change. Terraform will save this
47 // byte-for-byte and return it to the provider in the apply call.
51 // Decode unmarshals the raw representation of the instance object being
52 // changed. Pass the implied type of the corresponding resource type schema
53 // for correct operation.
54 func (rcs *ResourceInstanceChangeSrc) Decode(ty cty.Type) (*ResourceInstanceChange, error) {
55 change, err := rcs.ChangeSrc.Decode(ty)
59 return &ResourceInstanceChange{
61 DeposedKey: rcs.DeposedKey,
62 ProviderAddr: rcs.ProviderAddr,
64 RequiredReplace: rcs.RequiredReplace,
69 // DeepCopy creates a copy of the receiver where any pointers to nested mutable
70 // values are also copied, thus ensuring that future mutations of the receiver
71 // will not affect the copy.
73 // Some types used within a resource change are immutable by convention even
74 // though the Go language allows them to be mutated, such as the types from
75 // the addrs package. These are _not_ copied by this method, under the
76 // assumption that callers will behave themselves.
77 func (rcs *ResourceInstanceChangeSrc) DeepCopy() *ResourceInstanceChangeSrc {
83 ret.RequiredReplace = cty.NewPathSet(ret.RequiredReplace.List()...)
85 if len(ret.Private) != 0 {
86 private := make([]byte, len(ret.Private))
87 copy(private, ret.Private)
91 ret.ChangeSrc.Before = ret.ChangeSrc.Before.Copy()
92 ret.ChangeSrc.After = ret.ChangeSrc.After.Copy()
97 // OutputChangeSrc describes a change to an output value.
98 type OutputChangeSrc struct {
99 // Addr is the absolute address of the output value that the change
101 Addr addrs.AbsOutputValue
103 // ChangeSrc is an embedded description of the not-yet-decoded change.
105 // For output value changes, the type constraint for the DynamicValue
106 // instances is always cty.DynamicPseudoType.
109 // Sensitive, if true, indicates that either the old or new value in the
110 // change is sensitive and so a rendered version of the plan in the UI
111 // should elide the actual values while still indicating the action of the
116 // Decode unmarshals the raw representation of the output value being
118 func (ocs *OutputChangeSrc) Decode() (*OutputChange, error) {
119 change, err := ocs.ChangeSrc.Decode(cty.DynamicPseudoType)
123 return &OutputChange{
126 Sensitive: ocs.Sensitive,
130 // DeepCopy creates a copy of the receiver where any pointers to nested mutable
131 // values are also copied, thus ensuring that future mutations of the receiver
132 // will not affect the copy.
134 // Some types used within a resource change are immutable by convention even
135 // though the Go language allows them to be mutated, such as the types from
136 // the addrs package. These are _not_ copied by this method, under the
137 // assumption that callers will behave themselves.
138 func (ocs *OutputChangeSrc) DeepCopy() *OutputChangeSrc {
144 ret.ChangeSrc.Before = ret.ChangeSrc.Before.Copy()
145 ret.ChangeSrc.After = ret.ChangeSrc.After.Copy()
150 // ChangeSrc is a not-yet-decoded Change.
151 type ChangeSrc struct {
152 // Action defines what kind of change is being made.
155 // Before and After correspond to the fields of the same name in Change,
156 // but have not yet been decoded from the serialized value used for
158 Before, After DynamicValue
161 // Decode unmarshals the raw representations of the before and after values
162 // to produce a Change object. Pass the type constraint that the result must
165 // Where a ChangeSrc is embedded in some other struct, it's generally better
166 // to call the corresponding Decode method of that struct rather than working
167 // directly with its embedded Change.
168 func (cs *ChangeSrc) Decode(ty cty.Type) (*Change, error) {
170 before := cty.NullVal(ty)
171 after := cty.NullVal(ty)
173 if len(cs.Before) > 0 {
174 before, err = cs.Before.Decode(ty)
176 return nil, fmt.Errorf("error decoding 'before' value: %s", err)
179 if len(cs.After) > 0 {
180 after, err = cs.After.Decode(ty)
182 return nil, fmt.Errorf("error decoding 'after' value: %s", err)