mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
26f76dd222
While we're planning we must always update the state with the proposed new data resulting from the plan. In this case, we must record that the orphan instance doesn't exist at all in the proposed new state by storing its state as nil. This in turn allows references to the containing resource to evaluate properly, using the new updated resource count. This fixes TestContext2Apply_multiVarCountDec. This also includes a number of changes to the test output of TestContext2Apply_multiVarCountDec that make it easier to debug failures.
70 lines
2.1 KiB
Go
70 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, // Will point to a nil state after this complete, signalling destroyed
|
|
Output: &diff,
|
|
},
|
|
&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,
|
|
},
|
|
},
|
|
}
|
|
}
|