fix: refactor identity data handling and improve API response mapping

This commit is contained in:
Andre_Harms 2026-02-11 16:14:49 +01:00
parent be5c3b5430
commit 8b2d76482b
7 changed files with 87 additions and 35 deletions

View file

@ -179,7 +179,7 @@ func (r *userResource) Create(
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "region", region)
var roles []sqlserverflexalpha.UserRole
var roles []string
if !model.Roles.IsNull() && !model.Roles.IsUnknown() {
diags = model.Roles.ElementsAs(ctx, &roles, false)
resp.Diagnostics.Append(diags...)
@ -220,6 +220,18 @@ func (r *userResource) Create(
userId := *userResp.Id
ctx = tflog.SetField(ctx, "user_id", userId)
// Set data returned by API in identity
identity := UserResourceIdentityModel{
ProjectID: types.StringValue(projectId),
Region: types.StringValue(region),
InstanceID: types.StringValue(instanceId),
UserID: types.Int64Value(userResp.GetId()),
}
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
if resp.Diagnostics.HasError() {
return
}
// Map response body to schema
err = mapFieldsCreate(userResp, &model, region)
if err != nil {
@ -282,6 +294,18 @@ func (r *userResource) Read(
ctx = core.LogResponse(ctx)
// Set data returned by API in identity
identity := UserResourceIdentityModel{
ProjectID: types.StringValue(projectId),
Region: types.StringValue(region),
InstanceID: types.StringValue(instanceId),
UserID: types.Int64Value(userId),
}
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
if resp.Diagnostics.HasError() {
return
}
// Map response body to schema
err = mapFields(recordSetResp, &model, region)
if err != nil {
@ -351,6 +375,7 @@ func (r *userResource) Delete(
}
ctx = core.LogResponse(ctx)
resp.State.RemoveResource(ctx)
tflog.Info(ctx, "SQLServer Flex user deleted")
}