2018-07-21 02:15:03 +02:00
|
|
|
package plans
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
|
|
"github.com/hashicorp/terraform/states"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ResourceInstanceChangeSrc is a not-yet-decoded ResourceInstanceChange.
|
|
|
|
// Pass the associated resource type's schema type to method Decode to
|
2020-05-13 10:14:58 +02:00
|
|
|
// obtain a ResourceInstanceChange.
|
2018-07-21 02:15:03 +02:00
|
|
|
type ResourceInstanceChangeSrc struct {
|
|
|
|
// Addr is the absolute address of the resource instance that the change
|
|
|
|
// will apply to.
|
|
|
|
Addr addrs.AbsResourceInstance
|
|
|
|
|
|
|
|
// DeposedKey is the identifier for a deposed object associated with the
|
|
|
|
// given instance, or states.NotDeposed if this change applies to the
|
|
|
|
// current object.
|
|
|
|
//
|
|
|
|
// A Replace change for a resource with create_before_destroy set will
|
|
|
|
// create a new DeposedKey temporarily during replacement. In that case,
|
|
|
|
// DeposedKey in the plan is always states.NotDeposed, representing that
|
|
|
|
// the current object is being replaced with the deposed.
|
|
|
|
DeposedKey states.DeposedKey
|
|
|
|
|
|
|
|
// Provider is the address of the provider configuration that was used
|
|
|
|
// to plan this change, and thus the configuration that must also be
|
|
|
|
// used to apply it.
|
|
|
|
ProviderAddr addrs.AbsProviderConfig
|
|
|
|
|
|
|
|
// ChangeSrc is an embedded description of the not-yet-decoded change.
|
|
|
|
ChangeSrc
|
2018-08-18 02:22:18 +02:00
|
|
|
|
2018-08-25 01:13:50 +02:00
|
|
|
// RequiredReplace is a set of paths that caused the change action to be
|
|
|
|
// Replace rather than Update. Always nil if the change action is not
|
|
|
|
// Replace.
|
|
|
|
//
|
|
|
|
// This is retained only for UI-plan-rendering purposes and so it does not
|
|
|
|
// currently survive a round-trip through a saved plan file.
|
2018-08-29 20:25:09 +02:00
|
|
|
RequiredReplace cty.PathSet
|
2018-08-25 01:13:50 +02:00
|
|
|
|
2018-08-18 02:22:18 +02:00
|
|
|
// Private allows a provider to stash any extra data that is opaque to
|
|
|
|
// Terraform that relates to this change. Terraform will save this
|
|
|
|
// byte-for-byte and return it to the provider in the apply call.
|
|
|
|
Private []byte
|
2018-07-21 02:15:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode unmarshals the raw representation of the instance object being
|
|
|
|
// changed. Pass the implied type of the corresponding resource type schema
|
|
|
|
// for correct operation.
|
|
|
|
func (rcs *ResourceInstanceChangeSrc) Decode(ty cty.Type) (*ResourceInstanceChange, error) {
|
|
|
|
change, err := rcs.ChangeSrc.Decode(ty)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &ResourceInstanceChange{
|
2018-08-25 01:13:50 +02:00
|
|
|
Addr: rcs.Addr,
|
|
|
|
DeposedKey: rcs.DeposedKey,
|
|
|
|
ProviderAddr: rcs.ProviderAddr,
|
|
|
|
Change: *change,
|
|
|
|
RequiredReplace: rcs.RequiredReplace,
|
|
|
|
Private: rcs.Private,
|
2018-07-21 02:15:03 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:33:08 +02:00
|
|
|
// DeepCopy creates a copy of the receiver where any pointers to nested mutable
|
|
|
|
// values are also copied, thus ensuring that future mutations of the receiver
|
|
|
|
// will not affect the copy.
|
|
|
|
//
|
|
|
|
// Some types used within a resource change are immutable by convention even
|
|
|
|
// though the Go language allows them to be mutated, such as the types from
|
|
|
|
// the addrs package. These are _not_ copied by this method, under the
|
|
|
|
// assumption that callers will behave themselves.
|
|
|
|
func (rcs *ResourceInstanceChangeSrc) DeepCopy() *ResourceInstanceChangeSrc {
|
|
|
|
if rcs == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := *rcs
|
|
|
|
|
2018-08-29 20:25:09 +02:00
|
|
|
ret.RequiredReplace = cty.NewPathSet(ret.RequiredReplace.List()...)
|
2018-08-27 23:33:08 +02:00
|
|
|
|
|
|
|
if len(ret.Private) != 0 {
|
|
|
|
private := make([]byte, len(ret.Private))
|
|
|
|
copy(private, ret.Private)
|
|
|
|
ret.Private = private
|
|
|
|
}
|
|
|
|
|
|
|
|
ret.ChangeSrc.Before = ret.ChangeSrc.Before.Copy()
|
|
|
|
ret.ChangeSrc.After = ret.ChangeSrc.After.Copy()
|
|
|
|
|
|
|
|
return &ret
|
|
|
|
}
|
|
|
|
|
2018-09-11 01:26:55 +02:00
|
|
|
// OutputChangeSrc describes a change to an output value.
|
2018-07-21 02:15:03 +02:00
|
|
|
type OutputChangeSrc struct {
|
2018-09-11 01:26:55 +02:00
|
|
|
// Addr is the absolute address of the output value that the change
|
|
|
|
// will apply to.
|
|
|
|
Addr addrs.AbsOutputValue
|
|
|
|
|
2018-07-21 02:15:03 +02:00
|
|
|
// ChangeSrc is an embedded description of the not-yet-decoded change.
|
|
|
|
//
|
|
|
|
// For output value changes, the type constraint for the DynamicValue
|
|
|
|
// instances is always cty.DynamicPseudoType.
|
|
|
|
ChangeSrc
|
|
|
|
|
|
|
|
// Sensitive, if true, indicates that either the old or new value in the
|
|
|
|
// change is sensitive and so a rendered version of the plan in the UI
|
|
|
|
// should elide the actual values while still indicating the action of the
|
|
|
|
// change.
|
|
|
|
Sensitive bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode unmarshals the raw representation of the output value being
|
|
|
|
// changed.
|
|
|
|
func (ocs *OutputChangeSrc) Decode() (*OutputChange, error) {
|
|
|
|
change, err := ocs.ChangeSrc.Decode(cty.DynamicPseudoType)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &OutputChange{
|
2018-09-11 01:26:55 +02:00
|
|
|
Addr: ocs.Addr,
|
2018-07-21 02:15:03 +02:00
|
|
|
Change: *change,
|
|
|
|
Sensitive: ocs.Sensitive,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2018-09-11 01:26:55 +02:00
|
|
|
// DeepCopy creates a copy of the receiver where any pointers to nested mutable
|
|
|
|
// values are also copied, thus ensuring that future mutations of the receiver
|
|
|
|
// will not affect the copy.
|
|
|
|
//
|
|
|
|
// Some types used within a resource change are immutable by convention even
|
|
|
|
// though the Go language allows them to be mutated, such as the types from
|
|
|
|
// the addrs package. These are _not_ copied by this method, under the
|
|
|
|
// assumption that callers will behave themselves.
|
|
|
|
func (ocs *OutputChangeSrc) DeepCopy() *OutputChangeSrc {
|
|
|
|
if ocs == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret := *ocs
|
|
|
|
|
|
|
|
ret.ChangeSrc.Before = ret.ChangeSrc.Before.Copy()
|
|
|
|
ret.ChangeSrc.After = ret.ChangeSrc.After.Copy()
|
|
|
|
|
|
|
|
return &ret
|
|
|
|
}
|
|
|
|
|
2018-07-21 02:15:03 +02:00
|
|
|
// ChangeSrc is a not-yet-decoded Change.
|
|
|
|
type ChangeSrc struct {
|
|
|
|
// Action defines what kind of change is being made.
|
|
|
|
Action Action
|
|
|
|
|
|
|
|
// Before and After correspond to the fields of the same name in Change,
|
|
|
|
// but have not yet been decoded from the serialized value used for
|
|
|
|
// storage.
|
|
|
|
Before, After DynamicValue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode unmarshals the raw representations of the before and after values
|
|
|
|
// to produce a Change object. Pass the type constraint that the result must
|
|
|
|
// conform to.
|
|
|
|
//
|
|
|
|
// Where a ChangeSrc is embedded in some other struct, it's generally better
|
|
|
|
// to call the corresponding Decode method of that struct rather than working
|
|
|
|
// directly with its embedded Change.
|
|
|
|
func (cs *ChangeSrc) Decode(ty cty.Type) (*Change, error) {
|
2018-12-20 19:06:53 +01:00
|
|
|
var err error
|
|
|
|
before := cty.NullVal(ty)
|
|
|
|
after := cty.NullVal(ty)
|
|
|
|
|
|
|
|
if len(cs.Before) > 0 {
|
|
|
|
before, err = cs.Before.Decode(ty)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error decoding 'before' value: %s", err)
|
|
|
|
}
|
2018-07-21 02:15:03 +02:00
|
|
|
}
|
2018-12-20 19:06:53 +01:00
|
|
|
if len(cs.After) > 0 {
|
|
|
|
after, err = cs.After.Decode(ty)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error decoding 'after' value: %s", err)
|
|
|
|
}
|
2018-07-21 02:15:03 +02:00
|
|
|
}
|
|
|
|
return &Change{
|
|
|
|
Action: cs.Action,
|
|
|
|
Before: before,
|
|
|
|
After: after,
|
|
|
|
}, nil
|
|
|
|
}
|