98 lines
2.5 KiB
Go
98 lines
2.5 KiB
Go
package sqlserverflexbeta
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
|
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
|
)
|
|
|
|
func mapResponseToModel(
|
|
ctx context.Context,
|
|
resp *sqlserverflexbeta.GetUserResponse,
|
|
m *dataSourceModel,
|
|
tfDiags diag.Diagnostics,
|
|
) error {
|
|
if resp == nil {
|
|
return fmt.Errorf("response is nil")
|
|
}
|
|
|
|
m.Id = types.Int64Value(resp.GetId())
|
|
m.UserId = types.Int64Value(resp.GetId())
|
|
m.Username = types.StringValue(resp.GetUsername())
|
|
m.Port = types.Int64Value(resp.GetPort())
|
|
m.Host = types.StringValue(resp.GetHost())
|
|
m.DefaultDatabase = types.StringValue(resp.GetDefaultDatabase())
|
|
m.Status = types.StringValue(resp.GetStatus())
|
|
|
|
if resp.Roles != nil {
|
|
roles, diags := types.ListValueFrom(ctx, types.StringType, *resp.Roles)
|
|
tfDiags.Append(diags...)
|
|
if tfDiags.HasError() {
|
|
return fmt.Errorf("failed to map roles")
|
|
}
|
|
m.Roles = roles
|
|
} else {
|
|
m.Roles = types.ListNull(types.StringType)
|
|
}
|
|
|
|
if resp.Status != nil {
|
|
m.Status = types.StringValue(*resp.Status)
|
|
} else {
|
|
m.Status = types.StringNull()
|
|
}
|
|
|
|
// TODO: complete and refactor
|
|
|
|
/*
|
|
sampleList, diags := types.ListValueFrom(ctx, types.StringType, resp.GetList())
|
|
tfDiags.Append(diags...)
|
|
if diags.HasError() {
|
|
return fmt.Errorf(
|
|
"error converting list response value",
|
|
)
|
|
}
|
|
sample, diags := sqlserverflexbetaResGen.NewSampleValue(
|
|
sqlserverflexbetaResGen.SampleValue{}.AttributeTypes(ctx),
|
|
map[string]attr.Value{
|
|
"field": types.StringValue(string(resp.GetField())),
|
|
},
|
|
)
|
|
tfDiags.Append(diags...)
|
|
if diags.HasError() {
|
|
return fmt.Errorf(
|
|
"error converting sample response value",
|
|
"sample",
|
|
types.StringValue(string(resp.GetField())),
|
|
)
|
|
}
|
|
m.Sample = sample
|
|
*/
|
|
return nil
|
|
}
|
|
|
|
//func toCreatePayload(
|
|
// ctx context.Context,
|
|
// model *resourceModel,
|
|
//) (*sqlserverflexbeta.CreateUserRequestPayload, error) {
|
|
// if model == nil {
|
|
// return nil, fmt.Errorf("nil model")
|
|
// }
|
|
//
|
|
// var roles []sqlserverflexbeta.UserRole
|
|
// if !model.Roles.IsNull() && !model.Roles.IsUnknown() {
|
|
// diags := model.Roles.ElementsAs(ctx, &roles, false)
|
|
// if diags.HasError() {
|
|
// return nil, fmt.Errorf("failed to convert roles: %v", diags)
|
|
// }
|
|
// }
|
|
//
|
|
// return &sqlserverflexbeta.CreateUserRequestPayload{
|
|
// DefaultDatabase: model.DefaultDatabase.ValueStringPointer(),
|
|
// Username: model.Username.ValueStringPointer(),
|
|
// Roles: &roles,
|
|
// }, nil
|
|
//}
|