Model apps as a set instead of an ordered list (#2)
ci/woodpecker/tag/release Pipeline was successful
ci/woodpecker/tag/release Pipeline was successful
The arrstack engine returns `apps` alphabetically sorted regardless of the order they were written in, so modelling it as an ordered List makes any config whose order differs fail apply with "Provider produced inconsistent result after apply" and produce perpetual re-diffs. `apps` is semantically a set of app names, so it is now modelled as one. - Changes the `apps` attribute on `arrstack_secret_backend_role` from `types.List`/`schema.ListAttribute` to `types.Set`/`schema.SetAttribute` - Reads engine responses back via `types.SetValueFrom` - Updates unit tests for the set type and adds an order-insensitivity test proving a sorted engine response equals a differently-ordered config value - No other resources or data sources use the List-of-apps pattern Reviewed-on: #2 Co-authored-by: unkin-agent <unkin-agent@unkin.net> Co-committed-by: unkin-agent <unkin-agent@unkin.net>
This commit was merged in pull request #2.
This commit is contained in:
@@ -25,7 +25,7 @@ type secretBackendRoleResource struct {
|
||||
type secretBackendRoleModel struct {
|
||||
Backend types.String `tfsdk:"backend"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Apps types.List `tfsdk:"apps"`
|
||||
Apps types.Set `tfsdk:"apps"`
|
||||
TTL types.Int64 `tfsdk:"ttl"`
|
||||
MaxTTL types.Int64 `tfsdk:"max_ttl"`
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func (r *secretBackendRoleResource) Schema(_ context.Context, _ resource.SchemaR
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
},
|
||||
},
|
||||
"apps": schema.ListAttribute{
|
||||
"apps": schema.SetAttribute{
|
||||
Description: "arr apps a generated key may access (subset of sonarr, radarr, prowlarr).",
|
||||
ElementType: types.StringType,
|
||||
Required: true,
|
||||
@@ -212,9 +212,9 @@ func applyRoleData(m *secretBackendRoleModel, role map[string]interface{}) diag.
|
||||
var diags diag.Diagnostics
|
||||
|
||||
apps := toStringSlice(role["apps"])
|
||||
appList, appDiags := types.ListValueFrom(context.Background(), types.StringType, apps)
|
||||
appSet, appDiags := types.SetValueFrom(context.Background(), types.StringType, apps)
|
||||
diags.Append(appDiags...)
|
||||
m.Apps = appList
|
||||
m.Apps = appSet
|
||||
|
||||
if n, ok := toInt64(role["ttl"]); ok && n != 0 {
|
||||
m.TTL = types.Int64Value(n)
|
||||
|
||||
Reference in New Issue
Block a user