@@ -325,7 +325,6 @@ func (c *Context) refreshOnlyPlan(config *configs.Config, prevRunState *states.S
325325
326326func (c * Context ) destroyPlan (config * configs.Config , prevRunState * states.State , opts * PlanOpts ) (* plans.Plan , tfdiags.Diagnostics ) {
327327 var diags tfdiags.Diagnostics
328- pendingPlan := & plans.Plan {}
329328
330329 if opts .Mode != plans .DestroyMode {
331330 panic (fmt .Sprintf ("called Context.destroyPlan with %s" , opts .Mode ))
@@ -373,18 +372,17 @@ func (c *Context) destroyPlan(config *configs.Config, prevRunState *states.State
373372 return nil , diags
374373 }
375374
376- // insert the refreshed state into the destroy plan result, and ignore
377- // the changes recorded from the refresh.
378- pendingPlan .PriorState = refreshPlan .PriorState .DeepCopy ()
379- pendingPlan .PrevRunState = refreshPlan .PrevRunState .DeepCopy ()
380- log .Printf ("[TRACE] Context.destroyPlan: now _really_ creating a destroy plan" )
381-
382375 // We'll use the refreshed state -- which is the "prior state" from
383- // the perspective of this "pending plan" -- as the starting state
376+ // the perspective of this "destroy plan" -- as the starting state
384377 // for our destroy-plan walk, so it can take into account if we
385378 // detected during refreshing that anything was already deleted outside
386379 // of Terraform.
387- priorState = pendingPlan .PriorState
380+ priorState = refreshPlan .PriorState .DeepCopy ()
381+
382+ // The refresh plan may have upgraded state for some resources, make
383+ // sure we store the new version.
384+ prevRunState = refreshPlan .PrevRunState .DeepCopy ()
385+ log .Printf ("[TRACE] Context.destroyPlan: now _really_ creating a destroy plan" )
388386 }
389387
390388 destroyPlan , walkDiags := c .planWalk (config , priorState , opts )
@@ -394,10 +392,10 @@ func (c *Context) destroyPlan(config *configs.Config, prevRunState *states.State
394392 }
395393
396394 if ! opts .SkipRefresh {
397- // If we didn't skip refreshing then we want the previous run state
398- // prior state to be the one we originally fed into the c.plan call
399- // above, not the refreshed version we used for the destroy walk .
400- destroyPlan .PrevRunState = pendingPlan . PrevRunState
395+ // If we didn't skip refreshing then we want the previous run state to
396+ // be the one we originally fed into the c.refreshOnlyPlan call above,
397+ // not the refreshed version we used for the destroy planWalk .
398+ destroyPlan .PrevRunState = prevRunState
401399 }
402400
403401 relevantAttrs , rDiags := c .relevantResourceAttrsForPlan (config , destroyPlan )
0 commit comments