Skip to content

Commit a3e8c17

Browse files
committed
fix(provider/app_installation): implement stable encoding of parameters object
1 parent e206535 commit a3e8c17

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

internal/provider/app_installation_model.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
contentfulManagement "github.com/cysp/terraform-provider-contentful/internal/contentful-management-go"
55
"github.com/cysp/terraform-provider-contentful/internal/provider/resource_app_installation"
6+
"github.com/cysp/terraform-provider-contentful/internal/provider/util"
67
"github.com/go-faster/jx"
78
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
89
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -11,9 +12,9 @@ import (
1112

1213
func ReadAppInstallationModel(model *resource_app_installation.AppInstallationModel, appInstallation contentfulManagement.AppInstallation) {
1314
// SpaceId, EnvironmentId and AppDefinitionId are all already known
14-
if appInstallation.Parameters.Set {
15+
if parameters, ok := appInstallation.Parameters.Get(); ok {
1516
encoder := jx.Encoder{}
16-
appInstallation.Parameters.Encode(&encoder)
17+
util.EncodeJxRawMapOrdered(&encoder, parameters)
1718
model.Parameters = jsontypes.NewNormalizedValue(encoder.String())
1819
} else {
1920
model.Parameters = jsontypes.NewNormalizedNull()

internal/provider/util/jx.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package util
2+
3+
import (
4+
"sort"
5+
6+
"github.com/go-faster/jx"
7+
)
8+
9+
func EncodeJxRawMapOrdered(encoder *jx.Encoder, object map[string]jx.Raw) {
10+
encoder.ObjStart()
11+
12+
keys := make([]string, 0, len(object))
13+
for k := range object {
14+
keys = append(keys, k)
15+
}
16+
17+
sort.Strings(keys)
18+
19+
for _, k := range keys {
20+
encoder.FieldStart(k)
21+
22+
elem := object[k]
23+
24+
if len(elem) != 0 {
25+
encoder.Raw(elem)
26+
}
27+
}
28+
29+
encoder.ObjEnd()
30+
}

0 commit comments

Comments
 (0)