Skip to content

Commit

Permalink
chore: sort maps by key (#791)
Browse files Browse the repository at this point in the history
Closes #757

Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
argoyle and eddycharly authored Nov 3, 2022
1 parent 8957125 commit 59419aa
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
10 changes: 9 additions & 1 deletion hack/gen-tf-code/templates/schema.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,16 @@ func (in map[string]{{ qualifiedName .Elem }}) []interface{} {
if in == nil {
return nil
}
keys := make([]string, 0, len(in))
for key := range in {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] < keys[j]
})
var out []interface{}
for key, in := range in {
for _, key := range keys {
in := in[key]
out = append(out, map[string]interface{}{
"key": key,
"value": {{ template "flattenElem" .Elem }},
Expand Down
11 changes: 10 additions & 1 deletion pkg/schemas/kops/DataSource_ClusterSpec.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schemas

import (
"reflect"
"sort"

. "github.com/eddycharly/terraform-provider-kops/pkg/schemas"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -1317,8 +1318,16 @@ func FlattenDataSourceClusterSpecInto(in kops.ClusterSpec, out map[string]interf
if in == nil {
return nil
}
keys := make([]string, 0, len(in))
for key := range in {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
var out []interface{}
for key, in := range in {
for _, key := range keys {
in := in[key]
out = append(out, map[string]interface{}{
"key": key,
"value": func(in []string) []interface{} {
Expand Down
11 changes: 10 additions & 1 deletion pkg/schemas/kops/DataSource_ContainerdConfig.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schemas

import (
"reflect"
"sort"

. "github.com/eddycharly/terraform-provider-kops/pkg/schemas"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -289,8 +290,16 @@ func FlattenDataSourceContainerdConfigInto(in kops.ContainerdConfig, out map[str
if in == nil {
return nil
}
keys := make([]string, 0, len(in))
for key := range in {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
var out []interface{}
for key, in := range in {
for _, key := range keys {
in := in[key]
out = append(out, map[string]interface{}{
"key": key,
"value": func(in []string) []interface{} {
Expand Down
11 changes: 10 additions & 1 deletion pkg/schemas/kops/DataSource_KubeDNSConfig.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schemas

import (
"reflect"
"sort"

. "github.com/eddycharly/terraform-provider-kops/pkg/schemas"
coreschemas "github.com/eddycharly/terraform-provider-kops/pkg/schemas/core"
Expand Down Expand Up @@ -277,8 +278,16 @@ func FlattenDataSourceKubeDNSConfigInto(in kops.KubeDNSConfig, out map[string]in
if in == nil {
return nil
}
keys := make([]string, 0, len(in))
for key := range in {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
var out []interface{}
for key, in := range in {
for _, key := range keys {
in := in[key]
out = append(out, map[string]interface{}{
"key": key,
"value": func(in []string) []interface{} {
Expand Down
11 changes: 10 additions & 1 deletion pkg/schemas/kops/Resource_ClusterSpec.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schemas

import (
"reflect"
"sort"

. "github.com/eddycharly/terraform-provider-kops/pkg/schemas"
"k8s.io/kops/pkg/apis/kops"
Expand Down Expand Up @@ -1235,8 +1236,16 @@ func FlattenResourceClusterSpecInto(in kops.ClusterSpec, out map[string]interfac
if in == nil {
return nil
}
keys := make([]string, 0, len(in))
for key := range in {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
var out []interface{}
for key, in := range in {
for _, key := range keys {
in := in[key]
out = append(out, map[string]interface{}{
"key": key,
"value": func(in []string) []interface{} {
Expand Down
11 changes: 10 additions & 1 deletion pkg/schemas/kops/Resource_ContainerdConfig.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schemas

import (
"reflect"
"sort"

. "github.com/eddycharly/terraform-provider-kops/pkg/schemas"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -289,8 +290,16 @@ func FlattenResourceContainerdConfigInto(in kops.ContainerdConfig, out map[strin
if in == nil {
return nil
}
keys := make([]string, 0, len(in))
for key := range in {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
var out []interface{}
for key, in := range in {
for _, key := range keys {
in := in[key]
out = append(out, map[string]interface{}{
"key": key,
"value": func(in []string) []interface{} {
Expand Down
11 changes: 10 additions & 1 deletion pkg/schemas/kops/Resource_KubeDNSConfig.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package schemas

import (
"reflect"
"sort"

. "github.com/eddycharly/terraform-provider-kops/pkg/schemas"
coreschemas "github.com/eddycharly/terraform-provider-kops/pkg/schemas/core"
Expand Down Expand Up @@ -277,8 +278,16 @@ func FlattenResourceKubeDNSConfigInto(in kops.KubeDNSConfig, out map[string]inte
if in == nil {
return nil
}
keys := make([]string, 0, len(in))
for key := range in {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] > keys[j]
})
var out []interface{}
for key, in := range in {
for _, key := range keys {
in := in[key]
out = append(out, map[string]interface{}{
"key": key,
"value": func(in []string) []interface{} {
Expand Down

0 comments on commit 59419aa

Please sign in to comment.