helper/resource: clearer destroy logic
This commit is contained in:
parent
cb591ab2df
commit
e392c349ef
|
@ -24,18 +24,21 @@ func (m *Map) Apply(
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Destroy {
|
if d.Destroy {
|
||||||
// If we're destroying a resource that doesn't exist, then we're
|
if s.ID != "" {
|
||||||
// already done.
|
// Destroy the resource if it is created
|
||||||
if s.ID == "" {
|
err := r.Destroy(s, meta)
|
||||||
return nil, nil
|
if err != nil {
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.ID = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise call the destroy function
|
// If we're only destroying, and not creating, then return now.
|
||||||
err := r.Destroy(s, meta)
|
// Otherwise, we continue so that we can create a new resource.
|
||||||
if err == nil {
|
if !d.RequiresNew() {
|
||||||
s = nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return s, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.ID == "" {
|
if s.ID == "" {
|
||||||
|
|
Loading…
Reference in New Issue