mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
fb70eaa7d1
The earlier change 5f07201a made it so that the state is always rewritten by EvalDiffDestroy, but that was too disruptive to other users of EvalDiffDestroy. Now we follow the lead of EvalDiff and have a separate pointer for the _output_ state, which allows the caller to opt in to having its state pointer updated to reflect the new (nil) state. NodePlannableResourceInstanceOrphan is the only caller that currently opts in to this, since that was the focus of 5f07201a. We may need to make a similar change to other plannable resource destroy nodes, but we'll wait to see if that needs to be done in a subsequent commit.
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package terraform
|
|
|
|
// NodePlannableResourceInstanceOrphan represents a resource that is "applyable":
|
|
// it is ready to be applied and is represented by a diff.
|
|
type NodePlannableResourceInstanceOrphan struct {
|
|
*NodeAbstractResourceInstance
|
|
}
|
|
|
|
var (
|
|
_ GraphNodeSubPath = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
_ GraphNodeReferenceable = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
_ GraphNodeReferencer = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
_ GraphNodeResource = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
_ GraphNodeResourceInstance = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
_ GraphNodeAttachResourceConfig = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
_ GraphNodeAttachResourceState = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
_ GraphNodeEvalable = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
)
|
|
|
|
var (
|
|
_ GraphNodeEvalable = (*NodePlannableResourceInstanceOrphan)(nil)
|
|
)
|
|
|
|
func (n *NodePlannableResourceInstanceOrphan) Name() string {
|
|
return n.ResourceInstanceAddr().String() + " (orphan)"
|
|
}
|
|
|
|
// GraphNodeEvalable
|
|
func (n *NodePlannableResourceInstanceOrphan) EvalTree() EvalNode {
|
|
addr := n.ResourceInstanceAddr()
|
|
|
|
// State still uses legacy-style internal ids, so we need to shim to get
|
|
// a suitable key to use.
|
|
stateId := NewLegacyResourceInstanceAddress(addr).stateId()
|
|
|
|
// Declare a bunch of variables that are used for state during
|
|
// evaluation. Most of this are written to by-address below.
|
|
var diff *InstanceDiff
|
|
var state *InstanceState
|
|
|
|
return &EvalSequence{
|
|
Nodes: []EvalNode{
|
|
&EvalReadState{
|
|
Name: stateId,
|
|
Output: &state,
|
|
},
|
|
&EvalDiffDestroy{
|
|
Addr: addr.Resource,
|
|
State: &state,
|
|
Output: &diff,
|
|
OutputState: &state, // Will point to a nil state after this complete, signalling destroyed
|
|
},
|
|
&EvalCheckPreventDestroy{
|
|
Addr: addr.Resource,
|
|
Config: n.Config,
|
|
Diff: &diff,
|
|
},
|
|
&EvalWriteDiff{
|
|
Name: stateId,
|
|
Diff: &diff,
|
|
},
|
|
&EvalWriteState{
|
|
Name: stateId,
|
|
ResourceType: addr.Resource.Resource.Type,
|
|
Provider: n.ResolvedProvider,
|
|
State: &state,
|
|
},
|
|
},
|
|
}
|
|
}
|