diff --git a/terraform/state.go b/terraform/state.go index 41a889e83..5fa74a79f 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -2074,7 +2074,7 @@ func (r resourceNameSort) Less(i, j int) bool { } } - return false + return r[i] < r[j] } // moduleStateSort implements sort.Interface to sort module states diff --git a/terraform/state_test.go b/terraform/state_test.go index b0ed35368..c10ebf133 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "reflect" + "sort" "strings" "testing" @@ -1896,3 +1897,37 @@ func TestReadState_prune(t *testing.T) { t.Fatalf("got:\n%#v", actual) } } + +func TestResourceNameSort(t *testing.T) { + names := []string{ + "a", + "b", + "a.0", + "a.c", + "a.d", + "c", + "a.b.0", + "a.b.1", + "a.b.10", + "a.b.2", + } + + sort.Sort(resourceNameSort(names)) + + expected := []string{ + "a", + "a.0", + "a.b.0", + "a.b.1", + "a.b.2", + "a.b.10", + "a.c", + "a.d", + "b", + "c", + } + + if !reflect.DeepEqual(names, expected) { + t.Fatalf("got: %q\nexpected: %q\n", names, expected) + } +}