From e392c349efc3c42762223e6395a1da301af32bdb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Jun 2014 12:59:50 -0700 Subject: [PATCH] helper/resource: clearer destroy logic --- helper/resource/map.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/helper/resource/map.go b/helper/resource/map.go index ea1860e48..944668ccf 100644 --- a/helper/resource/map.go +++ b/helper/resource/map.go @@ -24,18 +24,21 @@ func (m *Map) Apply( } if d.Destroy { - // If we're destroying a resource that doesn't exist, then we're - // already done. - if s.ID == "" { - return nil, nil + if s.ID != "" { + // Destroy the resource if it is created + err := r.Destroy(s, meta) + if err != nil { + return s, err + } + + s.ID = "" } - // Otherwise call the destroy function - err := r.Destroy(s, meta) - if err == nil { - s = nil + // If we're only destroying, and not creating, then return now. + // Otherwise, we continue so that we can create a new resource. + if !d.RequiresNew() { + return nil, nil } - return s, err } if s.ID == "" {