core: Separate resource lifecycle for data vs. managed resources
The key difference between data and managed resources is in their respective lifecycles. Now the expanded resource EvalTree switches on the resource mode, generating a different lifecycle for each mode. For this initial change only managed resources are implemented, using the same implementation as before; data resources are no-ops. The data resource implementation will follow in a subsequent change.
This commit is contained in:
parent
c1315b3f09
commit
1da560b653
|
@ -195,10 +195,8 @@ func (n *graphNodeExpandedResource) StateDependencies() []string {
|
||||||
|
|
||||||
// GraphNodeEvalable impl.
|
// GraphNodeEvalable impl.
|
||||||
func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
var diff *InstanceDiff
|
|
||||||
var provider ResourceProvider
|
var provider ResourceProvider
|
||||||
var resourceConfig *ResourceConfig
|
var resourceConfig *ResourceConfig
|
||||||
var state *InstanceState
|
|
||||||
|
|
||||||
// Build the resource. If we aren't part of a multi-resource, then
|
// Build the resource. If we aren't part of a multi-resource, then
|
||||||
// we still consider ourselves as count index zero.
|
// we still consider ourselves as count index zero.
|
||||||
|
@ -259,8 +257,34 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
info := n.instanceInfo()
|
info := n.instanceInfo()
|
||||||
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.Resource.Mode {
|
||||||
|
case config.ManagedResourceMode:
|
||||||
|
seq.Nodes = append(
|
||||||
|
seq.Nodes,
|
||||||
|
n.managedResourceEvalNodes(resource, info, resourceConfig)...,
|
||||||
|
)
|
||||||
|
case config.DataResourceMode:
|
||||||
|
seq.Nodes = append(
|
||||||
|
seq.Nodes,
|
||||||
|
n.dataResourceEvalNodes(resource, info, resourceConfig)...,
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
panic(fmt.Errorf("unsupported resource mode %s", n.Resource.Mode))
|
||||||
|
}
|
||||||
|
|
||||||
|
return seq
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *graphNodeExpandedResource) managedResourceEvalNodes(resource *Resource, info *InstanceInfo, resourceConfig *ResourceConfig) []EvalNode {
|
||||||
|
var diff *InstanceDiff
|
||||||
|
var provider ResourceProvider
|
||||||
|
var state *InstanceState
|
||||||
|
|
||||||
|
nodes := make([]EvalNode, 0, 5)
|
||||||
|
|
||||||
// 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{
|
||||||
|
@ -290,7 +314,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Diff the resource
|
// Diff the resource
|
||||||
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
nodes = append(nodes, &EvalOpFilter{
|
||||||
Ops: []walkOperation{walkPlan},
|
Ops: []walkOperation{walkPlan},
|
||||||
Node: &EvalSequence{
|
Node: &EvalSequence{
|
||||||
Nodes: []EvalNode{
|
Nodes: []EvalNode{
|
||||||
|
@ -343,7 +367,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Diff the resource for destruction
|
// Diff the resource for destruction
|
||||||
seq.Nodes = append(seq.Nodes, &EvalOpFilter{
|
nodes = append(nodes, &EvalOpFilter{
|
||||||
Ops: []walkOperation{walkPlanDestroy},
|
Ops: []walkOperation{walkPlanDestroy},
|
||||||
Node: &EvalSequence{
|
Node: &EvalSequence{
|
||||||
Nodes: []EvalNode{
|
Nodes: []EvalNode{
|
||||||
|
@ -374,7 +398,7 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
var createNew, tainted bool
|
var createNew, tainted bool
|
||||||
var createBeforeDestroyEnabled bool
|
var createBeforeDestroyEnabled bool
|
||||||
var wasChangeType DiffChangeType
|
var wasChangeType DiffChangeType
|
||||||
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{
|
||||||
|
@ -557,7 +581,17 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return seq
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *graphNodeExpandedResource) dataResourceEvalNodes(resource *Resource, info *InstanceInfo, resourceConfig *ResourceConfig) []EvalNode {
|
||||||
|
//var diff *InstanceDiff
|
||||||
|
//var provider ResourceProvider
|
||||||
|
//var state *InstanceState
|
||||||
|
|
||||||
|
nodes := make([]EvalNode, 0, 5)
|
||||||
|
|
||||||
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
// instanceInfo is used for EvalTree.
|
// instanceInfo is used for EvalTree.
|
||||||
|
|
Loading…
Reference in New Issue