fix: refactor identity data handling and improve API response mapping
This commit is contained in:
parent
be5c3b5430
commit
8b2d76482b
7 changed files with 87 additions and 35 deletions
|
|
@ -165,7 +165,7 @@ func mapFieldsCreate(userResp *sqlserverflexbeta.CreateUserResponse, model *reso
|
|||
// toCreatePayload converts a resourceModel to an API CreateUserRequestPayload.
|
||||
func toCreatePayload(
|
||||
model *resourceModel,
|
||||
roles []sqlserverflexbeta.UserRole,
|
||||
roles []string,
|
||||
) (*sqlserverflexbeta.CreateUserRequestPayload, error) {
|
||||
if model == nil {
|
||||
return nil, fmt.Errorf("nil model")
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ func (r *userResource) Create(
|
|||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
var roles []sqlserverflexbeta.UserRole
|
||||
var roles []string
|
||||
if !model.Roles.IsNull() && !model.Roles.IsUnknown() {
|
||||
diags = model.Roles.ElementsAs(ctx, &roles, false)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
|
@ -292,6 +292,18 @@ func (r *userResource) Read(
|
|||
return
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Set refreshed state
|
||||
diags = resp.State.Set(ctx, model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
|
@ -350,6 +362,8 @@ func (r *userResource) Delete(
|
|||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
resp.State.RemoveResource(ctx)
|
||||
|
||||
tflog.Info(ctx, "SQLServer Flex user deleted")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue