From 691bb6b9077483d3d78966f1d8cb8920879559cd Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 12 Dec 2019 15:03:32 -0500 Subject: [PATCH] use CreateBeforeDestroy from state If the resource was stored as CreateBeforeDestroy, use the same ordering regardless. This reversal will be taken care if more cleanly in state-only destroys, and with less risk. Don't use this commit as-is. --- terraform/node_resource_destroy.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/terraform/node_resource_destroy.go b/terraform/node_resource_destroy.go index 0374d83dd..3619671d8 100644 --- a/terraform/node_resource_destroy.go +++ b/terraform/node_resource_destroy.go @@ -56,12 +56,21 @@ func (n *NodeDestroyResourceInstance) CreateBeforeDestroy() bool { return *n.CreateBeforeDestroyOverride } - // If we have no config, we just assume no - if n.Config == nil || n.Config.Managed == nil { - return false + // Config takes precedence + if n.Config != nil && n.Config.Managed != nil { + return n.Config.Managed.CreateBeforeDestroy } - return n.Config.Managed.CreateBeforeDestroy + // Otherwise check the state for a stored destroy order + if rs := n.ResourceState; rs != nil { + if s := rs.Instance(n.InstanceKey); s != nil { + if s.Current != nil { + return s.Current.CreateBeforeDestroy + } + } + } + + return false } // GraphNodeDestroyerCBD