diff --git a/terraform/state.go b/terraform/state.go index f94d9bedc..5b695c33c 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -172,6 +172,9 @@ func (s *State) Equal(other *State) bool { } // If any of the modules are not equal, then this state isn't equal + if len(s.Modules) != len(other.Modules) { + return false + } for _, m := range s.Modules { // This isn't very optimal currently but works. otherM := other.ModuleByPath(m.Path) diff --git a/terraform/state_test.go b/terraform/state_test.go index aaa049f4b..ef2aa0b59 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -116,6 +116,19 @@ func TestStateEqual(t *testing.T) { Result bool One, Two *State }{ + // Nils + { + false, + nil, + &State{Version: 2}, + }, + + { + true, + nil, + nil, + }, + // Different versions { false, @@ -159,6 +172,9 @@ func TestStateEqual(t *testing.T) { if tc.One.Equal(tc.Two) != tc.Result { t.Fatalf("Bad: %d\n\n%s\n\n%s", i, tc.One.String(), tc.Two.String()) } + if tc.Two.Equal(tc.One) != tc.Result { + t.Fatalf("Bad: %d\n\n%s\n\n%s", i, tc.One.String(), tc.Two.String()) + } } }