## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #45
Reviewed-by: Andre_Harms <andre.harms@stackit.cloud>
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
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
|
|
//}
|