fix: try fix errors
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / CI run tests (pull_request) Failing after 24m13s
CI Workflow / CI run build and linting (pull_request) Successful in 26m11s
CI Workflow / Code coverage report (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 35m13s

This commit is contained in:
Marcel S. Henselin 2026-02-16 14:39:15 +01:00
parent d5644ec27f
commit 1451273760
14 changed files with 140 additions and 40 deletions

View file

@ -46,7 +46,9 @@ func mapDataSourceFields(userResp *sqlserverflexbeta.GetUserResponse, model *dat
model.Roles = types.List(types.SetNull(types.StringType))
} else {
var roles []attr.Value
for _, role := range *user.Roles {
resRoles := *user.Roles
slices.Sort(resRoles)
for _, role := range resRoles {
roles = append(roles, types.StringValue(string(role)))
}
rolesSet, diags := types.SetValue(types.StringType, roles)
@ -183,9 +185,14 @@ func toCreatePayload(
return nil, fmt.Errorf("nil model")
}
return &sqlserverflexbeta.CreateUserRequestPayload{
Username: conversion.StringValueToPointer(model.Username),
DefaultDatabase: conversion.StringValueToPointer(model.DefaultDatabase),
Roles: &roles,
}, nil
pl := sqlserverflexbeta.CreateUserRequestPayload{
Username: conversion.StringValueToPointer(model.Username),
Roles: &roles,
}
slices.Sort(roles)
if !model.DefaultDatabase.IsNull() || !model.DefaultDatabase.IsUnknown() {
pl.DefaultDatabase = conversion.StringValueToPointer(model.DefaultDatabase)
}
return &pl, nil
}

View file

@ -63,9 +63,9 @@ func TestMapDataSourceFields(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -138,7 +138,7 @@ func TestMapDataSourceFields(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
@ -204,9 +204,9 @@ func TestMapFieldsCreate(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -292,7 +292,7 @@ func TestMapFieldsCreate(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
@ -332,8 +332,8 @@ func TestMapFields(t *testing.T) {
"simple_values",
&sqlserverflexbeta.GetUserResponse{
Roles: &[]string{
"role_1",
"role_2",
"role_1",
"",
},
Username: utils.Ptr("username"),
@ -350,9 +350,9 @@ func TestMapFields(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -423,7 +423,7 @@ func TestMapFields(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}

View file

@ -2,6 +2,7 @@ fields:
- name: 'id'
modifiers:
- 'UseStateForUnknown'
- 'RequiresReplace'
- name: 'instance_id'
validators:
@ -22,6 +23,7 @@ fields:
- name: 'region'
modifiers:
- 'RequiresReplace'
- 'RequiresReplace'
- name: 'user_id'
modifiers:
@ -31,10 +33,12 @@ fields:
- name: 'username'
modifiers:
- 'UseStateForUnknown'
- 'RequiresReplace'
- name: 'roles'
modifiers:
- 'UseStateForUnknown'
- 'RequiresReplace'
- name: 'password'
modifiers:

View file

@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
@ -107,6 +108,38 @@ func (r *userResource) ModifyPlan(
return
}
// TODO: verify if this is needed - START
var configRoles []string
diags := configModel.Roles.ElementsAs(ctx, &configRoles, false)
resp.Diagnostics.Append(diags...)
if diags.HasError() {
return
}
var planRoles []string
diags = planModel.Roles.ElementsAs(ctx, &planRoles, false)
resp.Diagnostics.Append(diags...)
if diags.HasError() {
return
}
slices.Sort(configRoles)
slices.Sort(planRoles)
if !slices.Equal(configRoles, planRoles) {
var roles []attr.Value
for _, role := range configRoles {
roles = append(roles, types.StringValue(string(role)))
}
rolesSet, diags := types.SetValue(types.StringType, roles)
resp.Diagnostics.Append(diags...)
if diags.HasError() {
return
}
planModel.Roles = types.List(rolesSet)
}
// TODO: verify if this is needed - END
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
if resp.Diagnostics.HasError() {
return