From e35524c7f0590c7c0583f8a94f8bd8b76f3f2140 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 5 Oct 2020 10:40:14 -0400 Subject: [PATCH] use existing State rather than Change.Before The change was passed into the provisioner node because the normal NodeApplyableResourceInstance overwrites the prior state with the new state. This however doesn't matter here, because the resource destroy node does not do this. Also, even if the updated state were to be used for some reason with a create provisioner, it would be the correct state to use at that point. --- terraform/eval_apply.go | 5 +---- terraform/node_resource_apply_instance.go | 1 - terraform/node_resource_destroy.go | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 14da88ab1..c5b6a4cad 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -505,9 +505,6 @@ type EvalApplyProvisioners struct { // When is the type of provisioner to run at this point When configs.ProvisionerWhen - - // We use the stored change to get the previous resource values in the case of a destroy provisioner - Change *plans.ResourceInstanceChange } // TODO: test @@ -606,7 +603,7 @@ func (n *EvalApplyProvisioners) apply(ctx EvalContext, provs []*configs.Provisio // this self is only used for destroy provisioner evaluation, and must // refer to the last known value of the resource. - self := n.Change.Before + self := (*n.State).Value var evalScope func(EvalContext, hcl.Body, cty.Value, *configschema.Block) (cty.Value, tfdiags.Diagnostics) switch n.When { diff --git a/terraform/node_resource_apply_instance.go b/terraform/node_resource_apply_instance.go index 5a0dc61e8..a1d35b81a 100644 --- a/terraform/node_resource_apply_instance.go +++ b/terraform/node_resource_apply_instance.go @@ -394,7 +394,6 @@ func (n *NodeApplyableResourceInstance) managedResourceExecute(ctx EvalContext) CreateNew: &createNew, Error: &applyError, When: configs.ProvisionerWhenCreate, - Change: diffApply, } _, err = applyProvisioners.Eval(ctx) if err != nil { diff --git a/terraform/node_resource_destroy.go b/terraform/node_resource_destroy.go index 386d0fec2..c54bc0cec 100644 --- a/terraform/node_resource_destroy.go +++ b/terraform/node_resource_destroy.go @@ -193,7 +193,6 @@ func (n *NodeDestroyResourceInstance) Execute(ctx EvalContext, op walkOperation) ResourceConfig: n.Config, Error: &provisionerErr, When: configs.ProvisionerWhenDestroy, - Change: changeApply, } _, err := evalApplyProvisioners.Eval(ctx) if err != nil {