From 325de3ebebd6ff9b3673901a14ea01ce4eb4370b Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Mon, 23 Sep 2024 07:36:16 -0500 Subject: [PATCH] add sort --- env0/data_environment.go | 12 ++++++++++++ env0/data_environment_test.go | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/env0/data_environment.go b/env0/data_environment.go index da734373..6ccb0ee8 100644 --- a/env0/data_environment.go +++ b/env0/data_environment.go @@ -2,6 +2,8 @@ package env0 import ( "context" + "slices" + "strings" "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -158,6 +160,16 @@ func dataEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta inter } } + slices.SortFunc(subEnvironments, func(a, b interface{}) int { + amap := a.(map[string]interface{}) + bmap := b.(map[string]interface{}) + + aalias := amap["alias"].(string) + balias := bmap["alias"].(string) + + return strings.Compare(aalias, balias) + }) + d.Set("sub_environment_configuration", subEnvironments) templateId := environment.LatestDeploymentLog.BlueprintId diff --git a/env0/data_environment_test.go b/env0/data_environment_test.go index f1c9812e..ebb9ee3b 100644 --- a/env0/data_environment_test.go +++ b/env0/data_environment_test.go @@ -88,10 +88,10 @@ func TestEnvironmentDataSource(t *testing.T) { resource.TestCheckResourceAttr(accessor, "token_id", template.TokenId), resource.TestCheckResourceAttr(accessor, "github_installation_id", strconv.Itoa(template.GithubInstallationId)), resource.TestCheckResourceAttr(accessor, "bitbucket_client_key", template.BitbucketClientKey), - resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.alias", "db"), - resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.id", "id_db"), - resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.1.alias", "compute"), - resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.1.id", "id_compute"), + resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.alias", "compute"), + resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.id", "id_compute"), + resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.1.alias", "db"), + resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.1.id", "id_db"), ), }, },