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

@ -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)