From ac9a049d19395105b2a2ed9782d05409dee1eaca Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 20 Oct 2016 21:39:55 -0700 Subject: [PATCH] terraform: Diff.Equal ignores ModuleDiff.Destroy This is necessary to get the shadow working properly with the destroy graph since the destroy graph doesn't set this field but the end state is still the same. --- terraform/diff.go | 14 +++++++++++++- terraform/diff_test.go | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/terraform/diff.go b/terraform/diff.go index 89dc947feb..a50c0b82b3 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -100,8 +100,20 @@ func (d *Diff) Equal(d2 *Diff) bool { sort.Sort(moduleDiffSort(d.Modules)) sort.Sort(moduleDiffSort(d2.Modules)) + // Copy since we have to modify the module destroy flag to false so + // we don't compare that. TODO: delete this when we get rid of the + // destroy flag on modules. + dCopy := d.DeepCopy() + d2Copy := d2.DeepCopy() + for _, m := range dCopy.Modules { + m.Destroy = false + } + for _, m := range d2Copy.Modules { + m.Destroy = false + } + // Use DeepEqual - return reflect.DeepEqual(d, d2) + return reflect.DeepEqual(dCopy, d2Copy) } // DeepCopy performs a deep copy of all parts of the Diff, making the diff --git a/terraform/diff_test.go b/terraform/diff_test.go index a9cb8b47b0..0970609aa7 100644 --- a/terraform/diff_test.go +++ b/terraform/diff_test.go @@ -77,6 +77,20 @@ func TestDiffEqual(t *testing.T) { }, true, }, + + "different module diff destroys": { + &Diff{ + Modules: []*ModuleDiff{ + &ModuleDiff{Path: []string{"root", "foo"}, Destroy: true}, + }, + }, + &Diff{ + Modules: []*ModuleDiff{ + &ModuleDiff{Path: []string{"root", "foo"}, Destroy: false}, + }, + }, + true, + }, } for name, tc := range cases {