From 4147500fcc1dfd8f22f3bb23bf28c68d0bb33791 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 25 Jun 2014 22:10:25 -0700 Subject: [PATCH] terraform: diff is not empty if it has to destroy --- terraform/diff.go | 2 +- terraform/terraform.go | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/terraform/diff.go b/terraform/diff.go index dbc310ea1..fd651f40f 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -76,7 +76,7 @@ func (d *Diff) Empty() bool { } for _, rd := range d.Resources { - if len(rd.Attributes) > 0 { + if !rd.Empty() { return false } } diff --git a/terraform/terraform.go b/terraform/terraform.go index fdebe4f5a..faed01158 100644 --- a/terraform/terraform.go +++ b/terraform/terraform.go @@ -228,9 +228,13 @@ func (t *Terraform) planWalkFn( var diff *ResourceDiff if r.Config == nil { + log.Printf("[DEBUG] %s: Orphan, marking for destroy", r.Id) + // This is an orphan (no config), so we mark it to be destroyed diff = &ResourceDiff{Destroy: true} } else { + log.Printf("[DEBUG] %s: Executing diff", r.Id) + // Get a diff from the newest state var err error diff, err = r.Provider.Diff(r.State, r.Config) @@ -312,15 +316,20 @@ func (t *Terraform) genericWalkFn( } // Make sure that at least some resource configuration is set - if rn.Resource.Config == nil && !rn.Orphan { - if rn.Config == nil { - rn.Resource.Config = new(ResourceConfig) - } else { - rn.Resource.Config = NewResourceConfig(rn.Config.RawConfig) + if !rn.Orphan { + if rn.Resource.Config == nil { + if rn.Config == nil { + rn.Resource.Config = new(ResourceConfig) + } else { + rn.Resource.Config = NewResourceConfig(rn.Config.RawConfig) + } } + } else { + rn.Resource.Config = nil } // Call the callack + log.Printf("Walking: %s", rn.Resource.Id) newVars, err := cb(rn.Resource) if err != nil { return err