Skip to content

Commit 6ff8e76

Browse files
authored
Fix List Issue (#281)
- Fix issue where reordering of lists on the Powerscale size causes state issues.
1 parent a66239b commit 6ff8e76

20 files changed

+285
-32
lines changed

powerscale/helper/ads_provider_helper.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,17 @@ func IsGroupnetUpdated(groupnetInPlan string, groupnetInResp string) bool {
9595
}
9696
return groupnetInResp != groupnetInPlan
9797
}
98+
99+
// For List set explicitly from plan
100+
// This is to keep state in similar order to plan
101+
// Lists returned from the array are not always in the same order as they appear in the plan
102+
func AdsListsDiff(ctx context.Context, plan models.AdsProviderResourceModel, state *models.AdsProviderResourceModel) {
103+
state.ExtraExpectedSpns = ListCheck(plan.ExtraExpectedSpns, plan.ExtraExpectedSpns.ElementType(ctx))
104+
state.FindableGroups = ListCheck(plan.FindableGroups, plan.FindableGroups.ElementType(ctx))
105+
state.FindableUsers = ListCheck(plan.FindableUsers, plan.FindableUsers.ElementType(ctx))
106+
state.IgnoredTrustedDomains = ListCheck(plan.IgnoredTrustedDomains, plan.IgnoredTrustedDomains.ElementType(ctx))
107+
state.LookupDomains = ListCheck(plan.LookupDomains, plan.LookupDomains.ElementType(ctx))
108+
state.UnfindableGroups = ListCheck(plan.UnfindableGroups, plan.UnfindableGroups.ElementType(ctx))
109+
state.UnfindableUsers = ListCheck(plan.UnfindableUsers, plan.UnfindableUsers.ElementType(ctx))
110+
state.Spns = ListCheck(plan.Spns, plan.Spns.ElementType(ctx))
111+
}

powerscale/helper/helper.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,13 @@ func GetClusterVersion(ctx context.Context, client *client.Client) (string, erro
353353
}
354354
return clusterVersion.Nodes[0].Release, err
355355
}
356+
357+
// For List set explicitly from plan
358+
// This is to keep state in similar order to plan
359+
// Lists returned from the array are not always in the same order as they appear in the plan
360+
func ListCheck(list types.List, elementType attr.Type) types.List {
361+
if list.IsUnknown() {
362+
return types.ListNull(elementType)
363+
}
364+
return list
365+
}

powerscale/helper/network_pool_helper.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,13 @@ func DeleteNetworkPool(ctx context.Context, client *client.Client, npID string,
9292
_, err := client.PscaleOpenAPIClient.NetworkApi.DeleteNetworkv12GroupnetsGroupnetSubnetsSubnetPool(ctx, npID, groupnet, subnet).Execute()
9393
return err
9494
}
95+
96+
// For List set explicitly from plan
97+
// This is to keep state in similar order to plan
98+
// Lists returned from the array are not always in the same order as they appear in the plan
99+
func NetworkPoolListsDiff(ctx context.Context, plan models.NetworkPoolResourceModel, state *models.NetworkPoolResourceModel) {
100+
state.Ifaces = ListCheck(plan.Ifaces, plan.Ifaces.ElementType(ctx))
101+
state.Ranges = ListCheck(plan.Ranges, plan.Ranges.ElementType(ctx))
102+
state.ScDNSZoneAliases = ListCheck(plan.ScDNSZoneAliases, plan.ScDNSZoneAliases.ElementType(ctx))
103+
state.StaticRoutes = ListCheck(plan.StaticRoutes, plan.StaticRoutes.ElementType(ctx))
104+
}

powerscale/helper/nfs_export_helper.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ func FilterExports(paths []types.String, ids []types.Int64, exports []powerscale
211211
return filteredExports, nil
212212
}
213213

214+
// For List set explicitly from plan
215+
// This is to keep state in similar order to plan
216+
// Lists returned from the array are not always in the same order as they appear in the plan
217+
func NFSExportListsDiff(ctx context.Context, plan models.NfsExportResource, state *models.NfsExportResource) {
218+
state.Clients = ListCheck(plan.Clients, plan.Clients.ElementType(ctx))
219+
state.ConflictingPaths = ListCheck(plan.ConflictingPaths, plan.ConflictingPaths.ElementType(ctx))
220+
state.Paths = ListCheck(plan.Paths, plan.Paths.ElementType(ctx))
221+
state.ReadOnlyClients = ListCheck(plan.ReadOnlyClients, plan.ReadOnlyClients.ElementType(ctx))
222+
state.ReadWriteClients = ListCheck(plan.ReadWriteClients, plan.ReadWriteClients.ElementType(ctx))
223+
state.RootClients = ListCheck(plan.RootClients, plan.RootClients.ElementType(ctx))
224+
state.SecurityFlavors = ListCheck(plan.SecurityFlavors, plan.SecurityFlavors.ElementType(ctx))
225+
state.UnresolvedClients = ListCheck(plan.UnresolvedClients, plan.UnresolvedClients.ElementType(ctx))
226+
}
227+
214228
// ResolvePersonaDiff implement state
215229
// For nfs export persona info, response may only contain UID while type/username is given
216230
// Need to manually copy plan info to state, or state would keep the type/username as null, which is inconsistent.

powerscale/helper/ntp_settings_helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ func ResolveSettingsDiff(ctx context.Context, plan models.NfsexportsettingsModel
5555
state.MapFailure = assignKnownObjectToUnknown(ctx, plan.MapFailure, state.MapFailure)
5656
state.MapNonRoot = assignKnownObjectToUnknown(ctx, plan.MapNonRoot, state.MapNonRoot)
5757
state.MapRoot = assignKnownObjectToUnknown(ctx, plan.MapRoot, state.MapRoot)
58+
state.SecurityFlavors = ListCheck(plan.SecurityFlavors, plan.SecurityFlavors.ElementType(ctx))
5859
}

powerscale/helper/resource_helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ func ReadFromState(ctx context.Context, source, destination interface{}) error {
500500
return err
501501
}
502502
case basetypes.ListValue:
503+
503504
listVal, ok := sourceValue.Field(i).Interface().(basetypes.ListValue)
504505
if !ok || listVal.IsNull() || listVal.IsUnknown() {
505506
continue

powerscale/helper/smb_share_helper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,14 @@ func ListSmbShares(ctx context.Context, client *client.Client, smbFilter *models
105105
}
106106
return &totalSmbShares, nil
107107
}
108+
109+
// For List set explicitly from plan
110+
// This is to keep state in similar order to plan
111+
// Lists returned from the array are not always in the same order as they appear in the plan
112+
func SMBShareListsDiff(ctx context.Context, plan models.SmbShareResource, state *models.SmbShareResource) {
113+
state.FileFilterExtensions = ListCheck(plan.FileFilterExtensions, plan.FileFilterExtensions.ElementType(ctx))
114+
state.HostACL = ListCheck(plan.HostACL, plan.HostACL.ElementType(ctx))
115+
state.MangleMap = ListCheck(plan.MangleMap, plan.MangleMap.ElementType(ctx))
116+
state.Permissions = ListCheck(plan.Permissions, plan.Permissions.ElementType(ctx))
117+
state.RunAsRoot = ListCheck(plan.RunAsRoot, plan.RunAsRoot.ElementType(ctx))
118+
}

powerscale/helper/smb_share_settings_helper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ func FilterSmbShareSettings(ctx context.Context, client *client.Client, filter *
6868
smbShareSettings, _, err := filterParam.Execute()
6969
return smbShareSettings, err
7070
}
71+
72+
// For List set explicitly from plan
73+
// This is to keep state in similar order to plan
74+
// Lists returned from the array are not always in the same order as they appear in the plan
75+
func SMBShareSettingsListsDiff(ctx context.Context, plan models.SmbShareSettingsResourceModel, state *models.SmbShareSettingsResourceModel) {
76+
state.FileFilterExtensions = ListCheck(plan.FileFilterExtensions, plan.FileFilterExtensions.ElementType(ctx))
77+
state.MangleMap = ListCheck(plan.MangleMap, plan.MangleMap.ElementType(ctx))
78+
state.HostACL = ListCheck(plan.HostACL, plan.HostACL.ElementType(ctx))
79+
}

powerscale/helper/storagepool_tier_helper.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import (
2121
"context"
2222
powerscale "dell/powerscale-go-client"
2323
"fmt"
24-
"github.com/hashicorp/terraform-plugin-framework/diag"
25-
"github.com/hashicorp/terraform-plugin-framework/types"
2624
"math"
2725
"strconv"
2826
"terraform-provider-powerscale/client"
2927
"terraform-provider-powerscale/powerscale/constants"
3028
"terraform-provider-powerscale/powerscale/models"
29+
30+
"github.com/hashicorp/terraform-plugin-framework/diag"
31+
"github.com/hashicorp/terraform-plugin-framework/types"
3132
)
3233

3334
// GetStoragepoolTier gets storage pool tier.
@@ -203,3 +204,11 @@ func GetStoragepoolTierByID(ctx context.Context, client *client.Client, id strin
203204

204205
return diags
205206
}
207+
208+
// For List set explicitly from plan
209+
// This is to keep state in similar order to plan
210+
// Lists returned from the array are not always in the same order as they appear in the plan
211+
func StoragepoolTierListsDiff(ctx context.Context, plan models.StoragepoolTierResourceModel, state *models.StoragepoolTierResourceModel) {
212+
state.Children = ListCheck(plan.Children, plan.Children.ElementType(ctx))
213+
state.Lnns = ListCheck(plan.Lnns, plan.Lnns.ElementType(ctx))
214+
}

powerscale/helper/subnet_helper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,12 @@ func DeleteSubnet(ctx context.Context, client *client.Client, subnetName, groupn
118118
_, err := client.PscaleOpenAPIClient.NetworkApi.DeleteNetworkv7GroupnetsGroupnetSubnet(ctx, subnetName, groupnet).Execute()
119119
return err
120120
}
121+
122+
// For List set explicitly from plan
123+
// This is to keep state in similar order to plan
124+
// Lists returned from the array are not always in the same order as they appear in the plan
125+
func SubnetListsDiff(ctx context.Context, plan models.V12GroupnetSubnetExtended, state *models.V12GroupnetSubnetExtended) {
126+
state.Pools = ListCheck(plan.Pools, plan.Pools.ElementType(ctx))
127+
state.ScServiceAddrs = ListCheck(plan.ScServiceAddrs, plan.ScServiceAddrs.ElementType(ctx))
128+
state.DsrAddrs = ListCheck(plan.DsrAddrs, plan.DsrAddrs.ElementType(ctx))
129+
}

0 commit comments

Comments
 (0)