Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: store deeply nested modules in a consistent order in the state #3573

Merged
merged 1 commit into from
Oct 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions terraform/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,9 +1207,8 @@ func (s moduleStateSort) Less(i, j int) bool {
return len(a.Path) < len(b.Path)
}

// Otherwise, compare by last path element
idx := len(a.Path) - 1
return a.Path[idx] < b.Path[idx]
// Otherwise, compare lexically
return strings.Join(a.Path, ".") < strings.Join(b.Path, ".")
}

func (s moduleStateSort) Swap(i, j int) {
Expand Down
17 changes: 17 additions & 0 deletions terraform/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ func TestStateAddModule(t *testing.T) {
[]string{"root", "foo", "bar"},
},
},
// Same last element, different middle element
{
[][]string{
[]string{"root", "foo", "bar"}, // This one should sort after...
[]string{"root", "foo"},
[]string{"root"},
[]string{"root", "bar", "bar"}, // ...this one.
[]string{"root", "bar"},
},
[][]string{
[]string{"root"},
[]string{"root", "bar"},
[]string{"root", "foo"},
[]string{"root", "bar", "bar"},
[]string{"root", "foo", "bar"},
},
},
}

for _, tc := range cases {
Expand Down