add evalWriteEmptyState for data source removal
This commit is contained in:
parent
7b8f13862c
commit
8850d787f4
|
@ -187,6 +187,18 @@ func (n *EvalUpdateStateHook) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// evalWriteEmptyState wraps EvalWriteState to specifically record an empty
|
||||||
|
// state for a particular object.
|
||||||
|
type evalWriteEmptyState struct {
|
||||||
|
EvalWriteState
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *evalWriteEmptyState) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
|
var state *states.ResourceInstanceObject
|
||||||
|
n.State = &state
|
||||||
|
return n.EvalWriteState.Eval(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// EvalWriteState is an EvalNode implementation that saves the given object
|
// EvalWriteState is an EvalNode implementation that saves the given object
|
||||||
// as the current object for the selected resource instance.
|
// as the current object for the selected resource instance.
|
||||||
type EvalWriteState struct {
|
type EvalWriteState struct {
|
||||||
|
|
|
@ -234,17 +234,16 @@ func (n *NodeDestroyResourceInstance) EvalTree() EvalNode {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Make sure we handle data sources properly.
|
// Managed resources need to be destroyed, while data sources
|
||||||
|
// are only removed from state.
|
||||||
&EvalIf{
|
&EvalIf{
|
||||||
If: func(ctx EvalContext) (bool, error) {
|
If: func(ctx EvalContext) (bool, error) {
|
||||||
if addr.Resource.Resource.Mode == addrs.DataResourceMode {
|
|
||||||
// deleting a data source is simply removing the state
|
|
||||||
state = nil
|
|
||||||
}
|
|
||||||
return addr.Resource.Resource.Mode == addrs.ManagedResourceMode, nil
|
return addr.Resource.Resource.Mode == addrs.ManagedResourceMode, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
Then: &EvalApply{
|
Then: &EvalSequence{
|
||||||
|
Nodes: []EvalNode{
|
||||||
|
&EvalApply{
|
||||||
Addr: addr.Resource,
|
Addr: addr.Resource,
|
||||||
Config: nil, // No configuration because we are destroying
|
Config: nil, // No configuration because we are destroying
|
||||||
State: &state,
|
State: &state,
|
||||||
|
@ -256,13 +255,23 @@ func (n *NodeDestroyResourceInstance) EvalTree() EvalNode {
|
||||||
Output: &state,
|
Output: &state,
|
||||||
Error: &err,
|
Error: &err,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
&EvalWriteState{
|
&EvalWriteState{
|
||||||
Addr: addr.Resource,
|
Addr: addr.Resource,
|
||||||
ProviderAddr: n.ResolvedProvider,
|
ProviderAddr: n.ResolvedProvider,
|
||||||
ProviderSchema: &providerSchema,
|
ProviderSchema: &providerSchema,
|
||||||
State: &state,
|
State: &state,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Else: &evalWriteEmptyState{
|
||||||
|
EvalWriteState{
|
||||||
|
Addr: addr.Resource,
|
||||||
|
ProviderAddr: n.ResolvedProvider,
|
||||||
|
ProviderSchema: &providerSchema,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
&EvalApplyPost{
|
&EvalApplyPost{
|
||||||
Addr: addr.Resource,
|
Addr: addr.Resource,
|
||||||
State: &state,
|
State: &state,
|
||||||
|
|
Loading…
Reference in New Issue