mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge branch 'b-data-resource-destroy'
This commit is contained in:
commit
50e095ddeb
@ -12,12 +12,14 @@ type EvalReadDataDiff struct {
|
|||||||
OutputState **InstanceState
|
OutputState **InstanceState
|
||||||
Config **ResourceConfig
|
Config **ResourceConfig
|
||||||
Info *InstanceInfo
|
Info *InstanceInfo
|
||||||
|
|
||||||
|
// Set Previous when re-evaluating diff during apply, to ensure that
|
||||||
|
// the "Destroy" flag is preserved.
|
||||||
|
Previous **InstanceDiff
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
|
func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
// TODO: test
|
// TODO: test
|
||||||
provider := *n.Provider
|
|
||||||
config := *n.Config
|
|
||||||
|
|
||||||
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
err := ctx.Hook(func(h Hook) (HookAction, error) {
|
||||||
return h.PreDiff(n.Info, nil)
|
return h.PreDiff(n.Info, nil)
|
||||||
@ -26,6 +28,16 @@ func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var diff *InstanceDiff
|
||||||
|
|
||||||
|
if n.Previous != nil && *n.Previous != nil && (*n.Previous).Destroy {
|
||||||
|
// If we're re-diffing for a diff that was already planning to
|
||||||
|
// destroy, then we'll just continue with that plan.
|
||||||
|
diff = &InstanceDiff{Destroy: true}
|
||||||
|
} else {
|
||||||
|
provider := *n.Provider
|
||||||
|
config := *n.Config
|
||||||
|
|
||||||
diff, err := provider.ReadDataDiff(n.Info, config)
|
diff, err := provider.ReadDataDiff(n.Info, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -42,6 +54,7 @@ func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
|
|||||||
RequiresNew: true,
|
RequiresNew: true,
|
||||||
Type: DiffAttrOutput,
|
Type: DiffAttrOutput,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = ctx.Hook(func(h Hook) (HookAction, error) {
|
err = ctx.Hook(func(h Hook) (HookAction, error) {
|
||||||
return h.PostDiff(n.Info, diff)
|
return h.PostDiff(n.Info, diff)
|
||||||
@ -83,7 +96,7 @@ func (n *EvalReadDataApply) Eval(ctx EvalContext) (interface{}, error) {
|
|||||||
// If the diff is for *destroying* this resource then we'll
|
// If the diff is for *destroying* this resource then we'll
|
||||||
// just drop its state and move on, since data resources don't
|
// just drop its state and move on, since data resources don't
|
||||||
// support an actual "destroy" action.
|
// support an actual "destroy" action.
|
||||||
if diff.Destroy {
|
if diff != nil && diff.Destroy {
|
||||||
if n.Output != nil {
|
if n.Output != nil {
|
||||||
*n.Output = nil
|
*n.Output = nil
|
||||||
}
|
}
|
||||||
|
@ -810,6 +810,7 @@ func (n *graphNodeExpandedResource) dataResourceEvalNodes(resource *Resource, in
|
|||||||
&EvalReadDataDiff{
|
&EvalReadDataDiff{
|
||||||
Info: info,
|
Info: info,
|
||||||
Config: &config,
|
Config: &config,
|
||||||
|
Previous: &diff,
|
||||||
Provider: &provider,
|
Provider: &provider,
|
||||||
Output: &diff,
|
Output: &diff,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user