From ad73d465da6a86546f4a9b103f6f7328bbb3e14a Mon Sep 17 00:00:00 2001 From: disc Date: Tue, 2 Nov 2021 23:27:12 +0200 Subject: [PATCH] Fixes #10 - Random reordering for server's attribute during the importing step because there is no previous (or setup in advance) state --- internal/provider/resource_server.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/provider/resource_server.go b/internal/provider/resource_server.go index 25f2d91..3d3c074 100644 --- a/internal/provider/resource_server.go +++ b/internal/provider/resource_server.go @@ -528,7 +528,12 @@ func resourceReadServer(ctx context.Context, d *schema.ResourceData, meta interf if !ok { return diag.Errorf("failed to parse organization_ids for the server: %s", server.Name) } - d.Set("organization_ids", matchStringEntitiesWithSchema(organizationsList, declaredOrganizations)) + + if len(declaredOrganizations) > 0 { + organizationsList = matchStringEntitiesWithSchema(organizationsList, declaredOrganizations) + } + + d.Set("organization_ids", organizationsList) } if len(server.Groups) > 0 { @@ -542,7 +547,12 @@ func resourceReadServer(ctx context.Context, d *schema.ResourceData, meta interf if !ok { return diag.Errorf("failed to parse groups for the server: %s", server.Name) } - d.Set("groups", matchStringEntitiesWithSchema(groupsList, declaredGroups)) + + if len(declaredGroups) > 0 { + groupsList = matchStringEntitiesWithSchema(groupsList, declaredGroups) + } + + d.Set("groups", groupsList) } if len(routes) > 0 { @@ -550,7 +560,12 @@ func resourceReadServer(ctx context.Context, d *schema.ResourceData, meta interf if !ok { return diag.Errorf("failed to parse routes for the server: %s", server.Name) } - d.Set("route", flattenRoutesData(matchRoutesWithSchema(routes, declaredRoutes))) + + if len(declaredRoutes) > 0 { + routes = matchRoutesWithSchema(routes, declaredRoutes) + } + + d.Set("route", flattenRoutesData(routes)) } if len(hosts) > 0 {