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.
This commit is contained in:
Mitchell Hashimoto 2016-10-20 21:39:55 -07:00
parent ceb613d449
commit ac9a049d19
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 27 additions and 1 deletions

View File

@ -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

View File

@ -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 {