feat: enhance database resource model with additional attributes and refactor data source schema

This commit is contained in:
Andre_Harms 2026-02-09 09:34:55 +01:00
parent c4891b770d
commit 1284bcc8a3
6 changed files with 66 additions and 80 deletions

View file

@ -2,9 +2,11 @@ package postgresflexalpha
import (
"fmt"
"strconv"
"github.com/hashicorp/terraform-plugin-framework/types"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
)
// mapFields maps fields from a ListDatabase API response to a ResourceModel for the data source.
@ -24,8 +26,8 @@ func mapFields(
}
var databaseId int64
if model.Id.ValueInt64() != 0 {
databaseId = model.Id.ValueInt64()
if model.DatabaseId.ValueInt64() != 0 {
databaseId = model.DatabaseId.ValueInt64()
} else if source.Id != nil {
databaseId = *source.Id
} else {
@ -33,10 +35,18 @@ func mapFields(
}
model.Id = types.Int64Value(databaseId)
model.DatabaseID = types.Int64Value(databaseId)
model.DatabaseId = types.Int64Value(databaseId)
model.Name = types.StringValue(source.GetName())
model.Owner = types.StringPointerValue(cleanString(source.Owner))
model.Region = types.StringValue(region)
model.ProjectId = types.StringValue(model.ProjectId.ValueString())
model.InstanceId = types.StringValue(model.InstanceId.ValueString())
model.TerraformID = utils.BuildInternalTerraformId(
model.ProjectId.ValueString(),
region,
model.InstanceId.ValueString(),
strconv.FormatInt(databaseId, 10),
)
return nil
}
@ -63,7 +73,7 @@ func mapResourceFields(source *postgresflexalpha.ListDatabase, model *ResourceMo
}
model.Id = types.Int64Value(databaseId)
model.DatabaseID = types.Int64Value(databaseId)
model.DatabaseId = types.Int64Value(databaseId)
model.Name = types.StringValue(source.GetName())
model.Owner = types.StringPointerValue(cleanString(source.Owner))
return nil