feat: add project_id and region attributes to database data source schema and refactor user model mapping

This commit is contained in:
Andre_Harms 2026-02-09 15:38:54 +01:00
parent 1284bcc8a3
commit f0e7c19cdf
8 changed files with 51 additions and 630 deletions

View file

@ -1,532 +0,0 @@
// Code generated by terraform-plugin-framework-generator DO NOT EDIT.
package postgresflexalpha
import (
"context"
"fmt"
"strings"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
func DatabaseDataSourceSchema(ctx context.Context) schema.Schema {
return schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
Computed: true,
Description: "The id of the database.",
MarkdownDescription: "The id of the database.",
},
"name": schema.StringAttribute{
Computed: true,
Description: "The name of the database.",
MarkdownDescription: "The name of the database.",
},
"owner": schema.StringAttribute{
Computed: true,
Description: "The owner of the database.",
MarkdownDescription: "The owner of the database.",
},
"database_id": schema.Int64Attribute{
Required: true,
Description: "The ID of the database.",
MarkdownDescription: "The ID of the database.",
},
"instance_id": schema.StringAttribute{
Required: true,
Description: "The ID of the instance.",
MarkdownDescription: "The ID of the instance.",
},
"project_id": schema.StringAttribute{
Required: true,
Description: "The STACKIT project ID.",
MarkdownDescription: "The STACKIT project ID.",
},
"region": schema.StringAttribute{
Required: true,
Description: "The region which should be addressed",
MarkdownDescription: "The region which should be addressed",
Validators: []validator.String{
stringvalidator.OneOf(
"eu01",
),
},
},
},
}
}
type DatabaseModel struct {
Id types.Int64 `tfsdk:"tf_original_api_id"`
Name types.String `tfsdk:"name"`
Owner types.String `tfsdk:"owner"`
DatabaseId types.Int64 `tfsdk:"database_id"`
InstanceId types.String `tfsdk:"instance_id"`
ProjectId types.String `tfsdk:"project_id"`
Region types.String `tfsdk:"region"`
}
var _ basetypes.ObjectTypable = DatabaseType{}
type DatabaseType struct {
basetypes.ObjectType
}
func (t DatabaseType) Equal(o attr.Type) bool {
other, ok := o.(DatabaseType)
if !ok {
return false
}
return t.ObjectType.Equal(other.ObjectType)
}
func (t DatabaseType) String() string {
return "DatabaseType"
}
func (t DatabaseType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (
basetypes.ObjectValuable,
diag.Diagnostics,
) {
var diags diag.Diagnostics
attributes := in.Attributes()
idAttribute, ok := attributes["id"]
if !ok {
diags.AddError(
"Attribute Missing",
`id is missing from object`,
)
return nil, diags
}
idVal, ok := idAttribute.(basetypes.Int64Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute),
)
}
nameAttribute, ok := attributes["name"]
if !ok {
diags.AddError(
"Attribute Missing",
`name is missing from object`,
)
return nil, diags
}
nameVal, ok := nameAttribute.(basetypes.StringValue)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute),
)
}
ownerAttribute, ok := attributes["owner"]
if !ok {
diags.AddError(
"Attribute Missing",
`owner is missing from object`,
)
return nil, diags
}
ownerVal, ok := ownerAttribute.(basetypes.StringValue)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute),
)
}
if diags.HasError() {
return nil, diags
}
return DatabaseValue{
Id: idVal,
Name: nameVal,
Owner: ownerVal,
state: attr.ValueStateKnown,
}, diags
}
func NewDatabaseValueNull() DatabaseValue {
return DatabaseValue{
state: attr.ValueStateNull,
}
}
func NewDatabaseValueUnknown() DatabaseValue {
return DatabaseValue{
state: attr.ValueStateUnknown,
}
}
func NewDatabaseValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (
DatabaseValue,
diag.Diagnostics,
) {
var diags diag.Diagnostics
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521
ctx := context.Background()
for name, attributeType := range attributeTypes {
attribute, ok := attributes[name]
if !ok {
diags.AddError(
"Missing DatabaseValue Attribute Value",
"While creating a DatabaseValue value, a missing attribute value was detected. "+
"A DatabaseValue must contain values for all attributes, even if null or unknown. "+
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
fmt.Sprintf("DatabaseValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()),
)
continue
}
if !attributeType.Equal(attribute.Type(ctx)) {
diags.AddError(
"Invalid DatabaseValue Attribute Type",
"While creating a DatabaseValue value, an invalid attribute value was detected. "+
"A DatabaseValue must use a matching attribute type for the value. "+
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
fmt.Sprintf("DatabaseValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+
fmt.Sprintf("DatabaseValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)),
)
}
}
for name := range attributes {
_, ok := attributeTypes[name]
if !ok {
diags.AddError(
"Extra DatabaseValue Attribute Value",
"While creating a DatabaseValue value, an extra attribute value was detected. "+
"A DatabaseValue must not contain values beyond the expected attribute types. "+
"This is always an issue with the provider and should be reported to the provider developers.\n\n"+
fmt.Sprintf("Extra DatabaseValue Attribute Name: %s", name),
)
}
}
if diags.HasError() {
return NewDatabaseValueUnknown(), diags
}
idAttribute, ok := attributes["id"]
if !ok {
diags.AddError(
"Attribute Missing",
`id is missing from object`,
)
return NewDatabaseValueUnknown(), diags
}
idVal, ok := idAttribute.(basetypes.Int64Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute),
)
}
nameAttribute, ok := attributes["name"]
if !ok {
diags.AddError(
"Attribute Missing",
`name is missing from object`,
)
return NewDatabaseValueUnknown(), diags
}
nameVal, ok := nameAttribute.(basetypes.StringValue)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute),
)
}
ownerAttribute, ok := attributes["owner"]
if !ok {
diags.AddError(
"Attribute Missing",
`owner is missing from object`,
)
return NewDatabaseValueUnknown(), diags
}
ownerVal, ok := ownerAttribute.(basetypes.StringValue)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute),
)
}
if diags.HasError() {
return NewDatabaseValueUnknown(), diags
}
return DatabaseValue{
Id: idVal,
Name: nameVal,
Owner: ownerVal,
state: attr.ValueStateKnown,
}, diags
}
func NewDatabaseValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) DatabaseValue {
object, diags := NewDatabaseValue(attributeTypes, attributes)
if diags.HasError() {
// This could potentially be added to the diag package.
diagsStrings := make([]string, 0, len(diags))
for _, diagnostic := range diags {
diagsStrings = append(
diagsStrings, fmt.Sprintf(
"%s | %s | %s",
diagnostic.Severity(),
diagnostic.Summary(),
diagnostic.Detail(),
),
)
}
panic("NewDatabaseValueMust received error(s): " + strings.Join(diagsStrings, "\n"))
}
return object
}
func (t DatabaseType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
if in.Type() == nil {
return NewDatabaseValueNull(), nil
}
if !in.Type().Equal(t.TerraformType(ctx)) {
return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type())
}
if !in.IsKnown() {
return NewDatabaseValueUnknown(), nil
}
if in.IsNull() {
return NewDatabaseValueNull(), nil
}
attributes := map[string]attr.Value{}
val := map[string]tftypes.Value{}
err := in.As(&val)
if err != nil {
return nil, err
}
for k, v := range val {
a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v)
if err != nil {
return nil, err
}
attributes[k] = a
}
return NewDatabaseValueMust(DatabaseValue{}.AttributeTypes(ctx), attributes), nil
}
func (t DatabaseType) ValueType(ctx context.Context) attr.Value {
return DatabaseValue{}
}
var _ basetypes.ObjectValuable = DatabaseValue{}
type DatabaseValue struct {
Id basetypes.Int64Value `tfsdk:"id"`
Name basetypes.StringValue `tfsdk:"name"`
Owner basetypes.StringValue `tfsdk:"owner"`
state attr.ValueState
}
func (v DatabaseValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
attrTypes := make(map[string]tftypes.Type, 3)
var val tftypes.Value
var err error
attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx)
attrTypes["owner"] = basetypes.StringType{}.TerraformType(ctx)
objectType := tftypes.Object{AttributeTypes: attrTypes}
switch v.state {
case attr.ValueStateKnown:
vals := make(map[string]tftypes.Value, 3)
val, err = v.Id.ToTerraformValue(ctx)
if err != nil {
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
}
vals["id"] = val
val, err = v.Name.ToTerraformValue(ctx)
if err != nil {
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
}
vals["name"] = val
val, err = v.Owner.ToTerraformValue(ctx)
if err != nil {
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
}
vals["owner"] = val
if err := tftypes.ValidateValue(objectType, vals); err != nil {
return tftypes.NewValue(objectType, tftypes.UnknownValue), err
}
return tftypes.NewValue(objectType, vals), nil
case attr.ValueStateNull:
return tftypes.NewValue(objectType, nil), nil
case attr.ValueStateUnknown:
return tftypes.NewValue(objectType, tftypes.UnknownValue), nil
default:
panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state))
}
}
func (v DatabaseValue) IsNull() bool {
return v.state == attr.ValueStateNull
}
func (v DatabaseValue) IsUnknown() bool {
return v.state == attr.ValueStateUnknown
}
func (v DatabaseValue) String() string {
return "DatabaseValue"
}
func (v DatabaseValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) {
var diags diag.Diagnostics
attributeTypes := map[string]attr.Type{
"id": basetypes.Int64Type{},
"name": basetypes.StringType{},
"owner": basetypes.StringType{},
}
if v.IsNull() {
return types.ObjectNull(attributeTypes), diags
}
if v.IsUnknown() {
return types.ObjectUnknown(attributeTypes), diags
}
objVal, diags := types.ObjectValue(
attributeTypes,
map[string]attr.Value{
"id": v.Id,
"name": v.Name,
"owner": v.Owner,
},
)
return objVal, diags
}
func (v DatabaseValue) Equal(o attr.Value) bool {
other, ok := o.(DatabaseValue)
if !ok {
return false
}
if v.state != other.state {
return false
}
if v.state != attr.ValueStateKnown {
return true
}
if !v.Id.Equal(other.Id) {
return false
}
if !v.Name.Equal(other.Name) {
return false
}
if !v.Owner.Equal(other.Owner) {
return false
}
return true
}
func (v DatabaseValue) Type(ctx context.Context) attr.Type {
return DatabaseType{
basetypes.ObjectType{
AttrTypes: v.AttributeTypes(ctx),
},
}
}
func (v DatabaseValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
return map[string]attr.Type{
"id": basetypes.Int64Type{},
"name": basetypes.StringType{},
"owner": basetypes.StringType{},
}
}

View file

@ -4,8 +4,8 @@ package postgresflexalpha
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@ -31,16 +31,29 @@ func DatabaseDataSourceSchema(ctx context.Context) schema.Schema {
},
"name": schema.StringAttribute{
Computed: true,
Optional: true,
Description: "The name of the database.",
MarkdownDescription: "The name of the database.",
},
"owner": schema.StringAttribute{
Optional: true,
Computed: true,
Description: "The owner of the database.",
MarkdownDescription: "The owner of the database.",
},
"project_id": schema.StringAttribute{
Required: true,
Description: "The STACKIT project ID.",
MarkdownDescription: "The STACKIT project ID.",
},
"region": schema.StringAttribute{
Required: true,
Description: "The region which should be addressed",
MarkdownDescription: "The region which should be addressed",
Validators: []validator.String{
stringvalidator.OneOf(
"eu01",
),
},
},
},
}
}
@ -51,7 +64,6 @@ type DatabaseModel struct {
InstanceId types.String `tfsdk:"instance_id"`
Name types.String `tfsdk:"name"`
Owner types.String `tfsdk:"owner"`
InstanceId types.String `tfsdk:"instance_id"`
ProjectId types.String `tfsdk:"project_id"`
Region types.String `tfsdk:"region"`
}

View file

@ -7,9 +7,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-go/tftypes"
"strings"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
)

View file

@ -178,23 +178,4 @@ func handleReadError(
http.StatusForbidden: fmt.Sprintf("Forbidden access to project %q.", projectId),
},
)
model.UserId = types.Int64Value(userId)
model.Username = types.StringPointerValue(user.Name)
if user.Roles == nil {
model.Roles = types.SetNull(types.StringType)
} else {
var roles []attr.Value
for _, role := range *user.Roles {
roles = append(roles, types.StringValue(string(role)))
}
rolesSet, diags := types.SetValue(types.StringType, roles)
if diags.HasError() {
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
}
model.Roles = rolesSet
}
model.Region = types.StringValue(region)
model.Status = types.StringPointerValue(user.Status)
return nil
}

View file

@ -53,11 +53,8 @@ func mapDataSourceFields(userResp *postgresflex.GetUserResponse, model *DataSour
}
model.Id = types.Int64Value(userId)
model.Host = types.StringValue(user.GetHost())
model.Port = types.Int64Value(user.GetPort())
model.Region = types.StringValue(region)
model.Status = types.StringValue(user.GetStatus())
model.ConnectionString = types.StringValue(user.GetConnectionString())
return nil
}
@ -141,10 +138,7 @@ func mapResourceFields(userResp *postgresflex.GetUserResponse, model *ResourceMo
}
model.Roles = types.List(rolesSet)
}
model.Host = types.StringPointerValue(user.Host)
model.Port = types.Int64PointerValue(user.Port)
model.Region = types.StringValue(region)
model.Status = types.StringPointerValue(user.Status)
model.ConnectionString = types.StringPointerValue(user.ConnectionString)
return nil
}

View file

@ -27,17 +27,14 @@ func TestMapDataSourceFields(t *testing.T) {
testRegion,
DataSourceModel{
UserModel: data.UserModel{
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringValue(""),
Roles: types.List(types.SetNull(types.StringType)),
Host: types.StringValue(""),
Port: types.Int64Value(0),
Status: types.StringValue(""),
Region: types.StringValue(testRegion),
ConnectionString: types.StringValue(""),
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringValue(""),
Roles: types.List(types.SetNull(types.StringType)),
Status: types.StringValue(""),
Region: types.StringValue(testRegion),
},
TerraformID: types.StringValue("pid,region,iid,1"),
},
@ -52,8 +49,6 @@ func TestMapDataSourceFields(t *testing.T) {
"",
},
Name: utils.Ptr("username"),
Host: utils.Ptr("host"),
Port: utils.Ptr(int64(1234)),
},
testRegion,
DataSourceModel{
@ -73,11 +68,8 @@ func TestMapDataSourceFields(t *testing.T) {
},
),
),
Host: types.StringValue("host"),
Port: types.Int64Value(1234),
Region: types.StringValue(testRegion),
Status: types.StringValue(""),
ConnectionString: types.StringValue(""),
Region: types.StringValue(testRegion),
Status: types.StringValue(""),
},
TerraformID: types.StringValue("pid,region,iid,1"),
},
@ -86,28 +78,22 @@ func TestMapDataSourceFields(t *testing.T) {
{
"null_fields_and_int_conversions",
&postgresflex.GetUserResponse{
Id: utils.Ptr(int64(1)),
Roles: &[]postgresflex.UserRole{},
Name: nil,
Host: nil,
Port: utils.Ptr(int64(2123456789)),
Status: utils.Ptr("status"),
ConnectionString: utils.Ptr("connection_string"),
Id: utils.Ptr(int64(1)),
Roles: &[]postgresflex.UserRole{},
Name: nil,
Status: utils.Ptr("status"),
},
testRegion,
DataSourceModel{
UserModel: data.UserModel{
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringValue(""),
Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})),
Host: types.StringValue(""),
Port: types.Int64Value(2123456789),
Region: types.StringValue(testRegion),
Status: types.StringValue("status"),
ConnectionString: types.StringValue("connection_string"),
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Name: types.StringValue(""),
Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})),
Region: types.StringValue(testRegion),
Status: types.StringValue("status"),
},
TerraformID: types.StringValue("pid,region,iid,1"),
},
@ -186,8 +172,6 @@ func TestMapFieldsCreate(t *testing.T) {
Name: types.StringNull(),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringNull(),
Host: types.StringNull(),
Port: types.Int64Null(),
Region: types.StringValue(testRegion),
Status: types.StringNull(),
ConnectionString: types.StringNull(),
@ -199,10 +183,9 @@ func TestMapFieldsCreate(t *testing.T) {
{
"simple_values",
&postgresflex.GetUserResponse{
Id: utils.Ptr(int64(1)),
Name: utils.Ptr("username"),
ConnectionString: utils.Ptr("connection_string"),
Status: utils.Ptr("status"),
Id: utils.Ptr(int64(1)),
Name: utils.Ptr("username"),
Status: utils.Ptr("status"),
},
testRegion,
ResourceModel{
@ -213,8 +196,6 @@ func TestMapFieldsCreate(t *testing.T) {
Name: types.StringValue("username"),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringNull(),
Host: types.StringNull(),
Port: types.Int64Null(),
Region: types.StringValue(testRegion),
Status: types.StringValue("status"),
ConnectionString: types.StringValue("connection_string"),
@ -226,10 +207,9 @@ func TestMapFieldsCreate(t *testing.T) {
{
"null_fields_and_int_conversions",
&postgresflex.GetUserResponse{
Id: utils.Ptr(int64(1)),
Name: nil,
ConnectionString: nil,
Status: nil,
Id: utils.Ptr(int64(1)),
Name: nil,
Status: nil,
},
testRegion,
ResourceModel{
@ -240,8 +220,6 @@ func TestMapFieldsCreate(t *testing.T) {
Name: types.StringNull(),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringNull(),
Host: types.StringNull(),
Port: types.Int64Null(),
Region: types.StringValue(testRegion),
Status: types.StringNull(),
ConnectionString: types.StringNull(),
@ -323,8 +301,6 @@ func TestMapFields(t *testing.T) {
ProjectId: types.StringValue("pid"),
Name: types.StringNull(),
Roles: types.List(types.SetNull(types.StringType)),
Host: types.StringNull(),
Port: types.Int64Null(),
Region: types.StringValue(testRegion),
Status: types.StringNull(),
ConnectionString: types.StringNull(),
@ -343,8 +319,6 @@ func TestMapFields(t *testing.T) {
"",
},
Name: utils.Ptr("username"),
Host: utils.Ptr("host"),
Port: utils.Ptr(int64(1234)),
},
testRegion,
ResourceModel{
@ -363,8 +337,6 @@ func TestMapFields(t *testing.T) {
},
),
),
Host: types.StringValue("host"),
Port: types.Int64Value(1234),
Region: types.StringValue(testRegion),
Status: types.StringNull(),
ConnectionString: types.StringNull(),
@ -378,8 +350,6 @@ func TestMapFields(t *testing.T) {
&postgresflex.GetUserResponse{
Id: utils.Ptr(int64(1)),
Name: nil,
Host: nil,
Port: utils.Ptr(int64(2123456789)),
},
testRegion,
ResourceModel{
@ -390,8 +360,6 @@ func TestMapFields(t *testing.T) {
ProjectId: types.StringValue("pid"),
Name: types.StringNull(),
Roles: types.List(types.SetNull(types.StringType)),
Host: types.StringNull(),
Port: types.Int64Value(2123456789),
Region: types.StringValue(testRegion),
Status: types.StringNull(),
ConnectionString: types.StringNull(),

View file

@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@ -558,7 +559,7 @@ func (r *userResource) ImportState(
tflog.Info(ctx, "postgresflexalpha user state imported")
}
func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region string) error {
func mapFields(userResp *postgresflex.GetUserResponse, model *ResourceModel, region string) error {
if userResp == nil {
return fmt.Errorf("response is nil")
}
@ -575,14 +576,14 @@ func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region stri
} else {
return fmt.Errorf("user id not present")
}
model.Id = utils.BuildInternalTerraformId(
model.TerraformID = utils.BuildInternalTerraformId(
model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), strconv.FormatInt(userId, 10),
)
model.UserId = types.Int64Value(userId)
model.Username = types.StringPointerValue(user.Name)
model.Name = types.StringPointerValue(user.Name)
if user.Roles == nil {
model.Roles = types.SetNull(types.StringType)
model.Roles = types.List(types.SetNull(types.StringType))
} else {
var roles []attr.Value
for _, role := range *user.Roles {
@ -592,7 +593,7 @@ func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region stri
if diags.HasError() {
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
}
model.Roles = rolesSet
model.Roles = types.List(rolesSet)
}
model.Region = types.StringValue(region)
model.Status = types.StringPointerValue(user.Status)