core: separate lifecycle for data resource "orphans"
The handling of data "orphans" is simpler than for managed resources because the only thing we need to deal with is our own state, and the validation pass guarantees that by the time we get to refresh or apply the instance state is no longer needed by any other resources and so we can safely drop it with no fanfare.
This commit is contained in:
parent
36054470e4
commit
4d50f22a23
|
@ -203,8 +203,6 @@ func (n *graphNodeOrphanResource) ProvidedBy() []string {
|
||||||
|
|
||||||
// GraphNodeEvalable impl.
|
// GraphNodeEvalable impl.
|
||||||
func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
||||||
var provider ResourceProvider
|
|
||||||
var state *InstanceState
|
|
||||||
|
|
||||||
seq := &EvalSequence{Nodes: make([]EvalNode, 0, 5)}
|
seq := &EvalSequence{Nodes: make([]EvalNode, 0, 5)}
|
||||||
|
|
||||||
|
@ -212,8 +210,33 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
||||||
info := &InstanceInfo{Id: n.ResourceKey.String(), Type: n.ResourceKey.Type}
|
info := &InstanceInfo{Id: n.ResourceKey.String(), Type: n.ResourceKey.Type}
|
||||||
seq.Nodes = append(seq.Nodes, &EvalInstanceInfo{Info: info})
|
seq.Nodes = append(seq.Nodes, &EvalInstanceInfo{Info: info})
|
||||||
|
|
||||||
|
// Each resource mode has its own lifecycle
|
||||||
|
switch n.ResourceKey.Mode {
|
||||||
|
case config.ManagedResourceMode:
|
||||||
|
seq.Nodes = append(
|
||||||
|
seq.Nodes,
|
||||||
|
n.managedResourceEvalNodes(info)...,
|
||||||
|
)
|
||||||
|
case config.DataResourceMode:
|
||||||
|
seq.Nodes = append(
|
||||||
|
seq.Nodes,
|
||||||
|
n.dataResourceEvalNodes(info)...,
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
panic(fmt.Errorf("unsupported resource mode %s", n.ResourceKey.Mode))
|
||||||
|
}
|
||||||
|
|
||||||
|
return seq
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *graphNodeOrphanResource) managedResourceEvalNodes(info *InstanceInfo) []EvalNode {
|
||||||
|
var provider ResourceProvider
|
||||||
|
var state *InstanceState
|
||||||
|
|
||||||
|
nodes := make([]EvalNode, 0, 3)
|
||||||
|
|
||||||
// Refresh the resource
|
// Refresh the resource
|
||||||
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
nodes = append(nodes, &EvalOpFilter{
|
||||||
Ops: []walkOperation{walkRefresh},
|
Ops: []walkOperation{walkRefresh},
|
||||||
Node: &EvalSequence{
|
Node: &EvalSequence{
|
||||||
Nodes: []EvalNode{
|
Nodes: []EvalNode{
|
||||||
|
@ -244,7 +267,7 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
||||||
|
|
||||||
// Diff the resource
|
// Diff the resource
|
||||||
var diff *InstanceDiff
|
var diff *InstanceDiff
|
||||||
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
nodes = append(nodes, &EvalOpFilter{
|
||||||
Ops: []walkOperation{walkPlan, walkPlanDestroy},
|
Ops: []walkOperation{walkPlan, walkPlanDestroy},
|
||||||
Node: &EvalSequence{
|
Node: &EvalSequence{
|
||||||
Nodes: []EvalNode{
|
Nodes: []EvalNode{
|
||||||
|
@ -267,7 +290,7 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
||||||
|
|
||||||
// Apply
|
// Apply
|
||||||
var err error
|
var err error
|
||||||
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
nodes = append(nodes, &EvalOpFilter{
|
||||||
Ops: []walkOperation{walkApply, walkDestroy},
|
Ops: []walkOperation{walkApply, walkDestroy},
|
||||||
Node: &EvalSequence{
|
Node: &EvalSequence{
|
||||||
Nodes: []EvalNode{
|
Nodes: []EvalNode{
|
||||||
|
@ -308,7 +331,35 @@ func (n *graphNodeOrphanResource) EvalTree() EvalNode {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return seq
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *graphNodeOrphanResource) dataResourceEvalNodes(info *InstanceInfo) []EvalNode {
|
||||||
|
nodes := make([]EvalNode, 0, 3)
|
||||||
|
|
||||||
|
// This will remain nil, since we don't retain states for orphaned
|
||||||
|
// data resources.
|
||||||
|
var state *InstanceState
|
||||||
|
|
||||||
|
// On both refresh and apply we just drop our state altogether,
|
||||||
|
// since the config resource validation pass will have proven that the
|
||||||
|
// resources remaining in the configuration don't need it.
|
||||||
|
nodes = append(nodes, &EvalOpFilter{
|
||||||
|
Ops: []walkOperation{walkRefresh, walkApply},
|
||||||
|
Node: &EvalSequence{
|
||||||
|
Nodes: []EvalNode{
|
||||||
|
&EvalWriteState{
|
||||||
|
Name: n.ResourceKey.String(),
|
||||||
|
ResourceType: n.ResourceKey.Type,
|
||||||
|
Provider: n.Provider,
|
||||||
|
Dependencies: n.DependentOn(),
|
||||||
|
State: &state, // state is nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *graphNodeOrphanResource) dependableName() string {
|
func (n *graphNodeOrphanResource) dependableName() string {
|
||||||
|
|
Loading…
Reference in New Issue