chore: work save
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m57s
CI Workflow / CI run tests (pull_request) Failing after 5m5s
CI Workflow / CI run build and linting (pull_request) Failing after 4m50s
CI Workflow / Code coverage report (pull_request) Has been skipped

This commit is contained in:
Marcel_Henselin 2026-03-05 15:11:15 +01:00
parent 411e99739a
commit d6d3a795bb
118 changed files with 3101 additions and 18065 deletions

View file

@ -6,8 +6,8 @@ import (
"net/http"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
"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/conversion"
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/datasources_gen"
postgresflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
@ -37,7 +37,7 @@ type dataSourceModel struct {
// instanceDataSource is the data source implementation.
type instanceDataSource struct {
client *postgresflexalpha.APIClient
client *v3alpha1api.APIClient
providerData core.ProviderData
}
@ -96,7 +96,7 @@ func (r *instanceDataSource) Read(
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "region", region)
instanceResp, err := r.client.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
instanceResp, err := r.client.DefaultAPI.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
if err != nil {
utils.LogError(
ctx,

View file

@ -40,7 +40,7 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
Description: "The host of the instance.",
MarkdownDescription: "The host of the instance.",
},
"port": schema.Int64Attribute{
"port": schema.Int32Attribute{
Computed: true,
Description: "The port of the instance.",
MarkdownDescription: "The port of the instance.",
@ -164,12 +164,12 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
),
},
},
"replicas": schema.Int64Attribute{
"replicas": schema.Int32Attribute{
Computed: true,
Description: "How many replicas the instance should have.",
MarkdownDescription: "How many replicas the instance should have.",
},
"retention_days": schema.Int64Attribute{
"retention_days": schema.Int32Attribute{
Computed: true,
Description: "How long backups are retained. The value can only be between 32 and 365 days.",
MarkdownDescription: "How long backups are retained. The value can only be between 32 and 365 days.",
@ -186,7 +186,7 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
Description: "The storage class for the storage.",
MarkdownDescription: "The storage class for the storage.",
},
"size": schema.Int64Attribute{
"size": schema.Int32Attribute{
Computed: true,
Description: "The storage size in Gigabytes.",
MarkdownDescription: "The storage size in Gigabytes.",
@ -223,8 +223,8 @@ type InstanceModel struct {
Network NetworkValue `tfsdk:"network"`
ProjectId types.String `tfsdk:"project_id"`
Region types.String `tfsdk:"region"`
Replicas types.Int64 `tfsdk:"replicas"`
RetentionDays types.Int64 `tfsdk:"retention_days"`
Replicas types.Int32 `tfsdk:"replicas"`
RetentionDays types.Int32 `tfsdk:"retention_days"`
Status types.String `tfsdk:"status"`
Storage StorageValue `tfsdk:"storage"`
Version types.String `tfsdk:"version"`
@ -634,12 +634,12 @@ func (t WriteType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue
return nil, diags
}
portVal, ok := portAttribute.(basetypes.Int64Value)
portVal, ok := portAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
fmt.Sprintf(`port expected to be basetypes.Int32Value, was: %T`, portAttribute))
}
if diags.HasError() {
@ -744,12 +744,12 @@ func NewWriteValue(attributeTypes map[string]attr.Type, attributes map[string]at
return NewWriteValueUnknown(), diags
}
portVal, ok := portAttribute.(basetypes.Int64Value)
portVal, ok := portAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
fmt.Sprintf(`port expected to be basetypes.Int32Value, was: %T`, portAttribute))
}
if diags.HasError() {
@ -832,7 +832,7 @@ var _ basetypes.ObjectValuable = WriteValue{}
type WriteValue struct {
Host basetypes.StringValue `tfsdk:"host"`
Port basetypes.Int64Value `tfsdk:"port"`
Port basetypes.Int32Value `tfsdk:"port"`
state attr.ValueState
}
@ -843,7 +843,7 @@ func (v WriteValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error)
var err error
attrTypes["host"] = basetypes.StringType{}.TerraformType(ctx)
attrTypes["port"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["port"] = basetypes.Int32Type{}.TerraformType(ctx)
objectType := tftypes.Object{AttributeTypes: attrTypes}
@ -898,7 +898,7 @@ func (v WriteValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, d
attributeTypes := map[string]attr.Type{
"host": basetypes.StringType{},
"port": basetypes.Int64Type{},
"port": basetypes.Int32Type{},
}
if v.IsNull() {
@ -956,7 +956,7 @@ func (v WriteValue) Type(ctx context.Context) attr.Type {
func (v WriteValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
return map[string]attr.Type{
"host": basetypes.StringType{},
"port": basetypes.Int64Type{},
"port": basetypes.Int32Type{},
}
}
@ -2020,12 +2020,12 @@ func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectVal
return nil, diags
}
sizeVal, ok := sizeAttribute.(basetypes.Int64Value)
sizeVal, ok := sizeAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute))
fmt.Sprintf(`size expected to be basetypes.Int32Value, was: %T`, sizeAttribute))
}
if diags.HasError() {
@ -2130,12 +2130,12 @@ func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]
return NewStorageValueUnknown(), diags
}
sizeVal, ok := sizeAttribute.(basetypes.Int64Value)
sizeVal, ok := sizeAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute))
fmt.Sprintf(`size expected to be basetypes.Int32Value, was: %T`, sizeAttribute))
}
if diags.HasError() {
@ -2218,7 +2218,7 @@ var _ basetypes.ObjectValuable = StorageValue{}
type StorageValue struct {
PerformanceClass basetypes.StringValue `tfsdk:"performance_class"`
Size basetypes.Int64Value `tfsdk:"size"`
Size basetypes.Int32Value `tfsdk:"size"`
state attr.ValueState
}
@ -2229,7 +2229,7 @@ func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, erro
var err error
attrTypes["performance_class"] = basetypes.StringType{}.TerraformType(ctx)
attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["size"] = basetypes.Int32Type{}.TerraformType(ctx)
objectType := tftypes.Object{AttributeTypes: attrTypes}
@ -2284,7 +2284,7 @@ func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue,
attributeTypes := map[string]attr.Type{
"performance_class": basetypes.StringType{},
"size": basetypes.Int64Type{},
"size": basetypes.Int32Type{},
}
if v.IsNull() {
@ -2342,6 +2342,6 @@ func (v StorageValue) Type(ctx context.Context) attr.Type {
func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
return map[string]attr.Type{
"performance_class": basetypes.StringType{},
"size": basetypes.Int64Type{},
"size": basetypes.Int32Type{},
}
}

View file

@ -54,7 +54,7 @@ func InstancesDataSourceSchema(ctx context.Context) schema.Schema {
Description: "List of owned instances and their current status.",
MarkdownDescription: "List of owned instances and their current status.",
},
"page": schema.Int64Attribute{
"page": schema.Int32Attribute{
Optional: true,
Computed: true,
Description: "Number of the page of items list to be returned.",
@ -62,19 +62,19 @@ func InstancesDataSourceSchema(ctx context.Context) schema.Schema {
},
"pagination": schema.SingleNestedAttribute{
Attributes: map[string]schema.Attribute{
"page": schema.Int64Attribute{
"page": schema.Int32Attribute{
Computed: true,
},
"size": schema.Int64Attribute{
"size": schema.Int32Attribute{
Computed: true,
},
"sort": schema.StringAttribute{
Computed: true,
},
"total_pages": schema.Int64Attribute{
"total_pages": schema.Int32Attribute{
Computed: true,
},
"total_rows": schema.Int64Attribute{
"total_rows": schema.Int32Attribute{
Computed: true,
},
},
@ -100,7 +100,7 @@ func InstancesDataSourceSchema(ctx context.Context) schema.Schema {
),
},
},
"size": schema.Int64Attribute{
"size": schema.Int32Attribute{
Optional: true,
Computed: true,
Description: "Number of items to be returned on each page.",
@ -130,11 +130,11 @@ func InstancesDataSourceSchema(ctx context.Context) schema.Schema {
type InstancesModel struct {
Instances types.List `tfsdk:"instances"`
Page types.Int64 `tfsdk:"page"`
Page types.Int32 `tfsdk:"page"`
Pagination PaginationValue `tfsdk:"pagination"`
ProjectId types.String `tfsdk:"project_id"`
Region types.String `tfsdk:"region"`
Size types.Int64 `tfsdk:"size"`
Size types.Int32 `tfsdk:"size"`
Sort types.String `tfsdk:"sort"`
}
@ -662,12 +662,12 @@ func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.Object
return nil, diags
}
pageVal, ok := pageAttribute.(basetypes.Int64Value)
pageVal, ok := pageAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute))
fmt.Sprintf(`page expected to be basetypes.Int32Value, was: %T`, pageAttribute))
}
sizeAttribute, ok := attributes["size"]
@ -680,12 +680,12 @@ func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.Object
return nil, diags
}
sizeVal, ok := sizeAttribute.(basetypes.Int64Value)
sizeVal, ok := sizeAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute))
fmt.Sprintf(`size expected to be basetypes.Int32Value, was: %T`, sizeAttribute))
}
sortAttribute, ok := attributes["sort"]
@ -716,12 +716,12 @@ func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.Object
return nil, diags
}
totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value)
totalPagesVal, ok := totalPagesAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute))
fmt.Sprintf(`total_pages expected to be basetypes.Int32Value, was: %T`, totalPagesAttribute))
}
totalRowsAttribute, ok := attributes["total_rows"]
@ -734,12 +734,12 @@ func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.Object
return nil, diags
}
totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value)
totalRowsVal, ok := totalRowsAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute))
fmt.Sprintf(`total_rows expected to be basetypes.Int32Value, was: %T`, totalRowsAttribute))
}
if diags.HasError() {
@ -829,12 +829,12 @@ func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[stri
return NewPaginationValueUnknown(), diags
}
pageVal, ok := pageAttribute.(basetypes.Int64Value)
pageVal, ok := pageAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute))
fmt.Sprintf(`page expected to be basetypes.Int32Value, was: %T`, pageAttribute))
}
sizeAttribute, ok := attributes["size"]
@ -847,12 +847,12 @@ func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[stri
return NewPaginationValueUnknown(), diags
}
sizeVal, ok := sizeAttribute.(basetypes.Int64Value)
sizeVal, ok := sizeAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute))
fmt.Sprintf(`size expected to be basetypes.Int32Value, was: %T`, sizeAttribute))
}
sortAttribute, ok := attributes["sort"]
@ -883,12 +883,12 @@ func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[stri
return NewPaginationValueUnknown(), diags
}
totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value)
totalPagesVal, ok := totalPagesAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute))
fmt.Sprintf(`total_pages expected to be basetypes.Int32Value, was: %T`, totalPagesAttribute))
}
totalRowsAttribute, ok := attributes["total_rows"]
@ -901,12 +901,12 @@ func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[stri
return NewPaginationValueUnknown(), diags
}
totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value)
totalRowsVal, ok := totalRowsAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute))
fmt.Sprintf(`total_rows expected to be basetypes.Int32Value, was: %T`, totalRowsAttribute))
}
if diags.HasError() {
@ -991,11 +991,11 @@ func (t PaginationType) ValueType(ctx context.Context) attr.Value {
var _ basetypes.ObjectValuable = PaginationValue{}
type PaginationValue struct {
Page basetypes.Int64Value `tfsdk:"page"`
Size basetypes.Int64Value `tfsdk:"size"`
Page basetypes.Int32Value `tfsdk:"page"`
Size basetypes.Int32Value `tfsdk:"size"`
Sort basetypes.StringValue `tfsdk:"sort"`
TotalPages basetypes.Int64Value `tfsdk:"total_pages"`
TotalRows basetypes.Int64Value `tfsdk:"total_rows"`
TotalPages basetypes.Int32Value `tfsdk:"total_pages"`
TotalRows basetypes.Int32Value `tfsdk:"total_rows"`
state attr.ValueState
}
@ -1005,11 +1005,11 @@ func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, e
var val tftypes.Value
var err error
attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["page"] = basetypes.Int32Type{}.TerraformType(ctx)
attrTypes["size"] = basetypes.Int32Type{}.TerraformType(ctx)
attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx)
attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["total_pages"] = basetypes.Int32Type{}.TerraformType(ctx)
attrTypes["total_rows"] = basetypes.Int32Type{}.TerraformType(ctx)
objectType := tftypes.Object{AttributeTypes: attrTypes}
@ -1087,11 +1087,11 @@ func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectVal
var diags diag.Diagnostics
attributeTypes := map[string]attr.Type{
"page": basetypes.Int64Type{},
"size": basetypes.Int64Type{},
"page": basetypes.Int32Type{},
"size": basetypes.Int32Type{},
"sort": basetypes.StringType{},
"total_pages": basetypes.Int64Type{},
"total_rows": basetypes.Int64Type{},
"total_pages": basetypes.Int32Type{},
"total_rows": basetypes.Int32Type{},
}
if v.IsNull() {
@ -1163,10 +1163,10 @@ func (v PaginationValue) Type(ctx context.Context) attr.Type {
func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
return map[string]attr.Type{
"page": basetypes.Int64Type{},
"size": basetypes.Int64Type{},
"page": basetypes.Int32Type{},
"size": basetypes.Int32Type{},
"sort": basetypes.StringType{},
"total_pages": basetypes.Int64Type{},
"total_rows": basetypes.Int64Type{},
"total_pages": basetypes.Int32Type{},
"total_rows": basetypes.Int32Type{},
}
}

View file

@ -7,8 +7,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
postgresflexalphadatasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/datasources_gen"
postgresflexalpharesource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
@ -33,9 +33,7 @@ func mapGetInstanceResponseToModel(
)
}
isConnectionInfoIncomplete := resp.ConnectionInfo == nil || resp.ConnectionInfo.Write == nil ||
resp.ConnectionInfo.Write.Host == nil || *resp.ConnectionInfo.Write.Host == "" ||
resp.ConnectionInfo.Write.Port == nil || *resp.ConnectionInfo.Write.Port == 0
isConnectionInfoIncomplete := resp.ConnectionInfo.Write.Host == "" || resp.ConnectionInfo.Write.Port == 0
if isConnectionInfoIncomplete {
m.ConnectionInfo = postgresflexalpharesource.NewConnectionInfoValueNull()
@ -46,8 +44,8 @@ func mapGetInstanceResponseToModel(
"write": postgresflexalpharesource.NewWriteValueMust(
postgresflexalpharesource.WriteValue{}.AttributeTypes(ctx),
map[string]attr.Value{
"host": types.StringPointerValue(resp.ConnectionInfo.Write.Host),
"port": types.Int64PointerValue(resp.ConnectionInfo.Write.Port),
"host": types.StringValue(resp.ConnectionInfo.Write.Host),
"port": types.Int32Value(resp.ConnectionInfo.Write.Port),
},
),
},
@ -62,7 +60,7 @@ func mapGetInstanceResponseToModel(
m.InstanceId.ValueString(),
)
}
m.InstanceId = types.StringPointerValue(resp.Id)
m.InstanceId = types.StringValue(resp.Id)
m.IsDeletable = types.BoolValue(resp.GetIsDeletable())
@ -75,12 +73,12 @@ func mapGetInstanceResponseToModel(
netInstAdd := types.StringValue("")
if instAdd, ok := resp.Network.GetInstanceAddressOk(); ok {
netInstAdd = types.StringValue(instAdd)
netInstAdd = types.StringValue(*instAdd)
}
netRtrAdd := types.StringValue("")
if rtrAdd, ok := resp.Network.GetRouterAddressOk(); ok {
netRtrAdd = types.StringValue(rtrAdd)
netRtrAdd = types.StringValue(*rtrAdd)
}
net, diags := postgresflexalpharesource.NewNetworkValue(
@ -97,8 +95,8 @@ func mapGetInstanceResponseToModel(
}
m.Network = net
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
m.RetentionDays = types.Int64Value(resp.GetRetentionDays())
m.Replicas = types.Int32Value(int32(resp.GetReplicas()))
m.RetentionDays = types.Int32Value(resp.GetRetentionDays())
m.Name = types.StringValue(resp.GetName())
@ -108,7 +106,7 @@ func mapGetInstanceResponseToModel(
postgresflexalpharesource.StorageValue{}.AttributeTypes(ctx),
map[string]attr.Value{
"performance_class": types.StringValue(resp.Storage.GetPerformanceClass()),
"size": types.Int64Value(resp.Storage.GetSize()),
"size": types.Int32Value(resp.Storage.GetSize()),
},
)
if diags.HasError() {
@ -131,7 +129,7 @@ func mapGetDataInstanceResponseToModel(
m.FlavorId = types.StringValue(resp.GetFlavorId())
m.Id = utils.BuildInternalTerraformId(m.ProjectId.ValueString(), m.Region.ValueString(), m.InstanceId.ValueString())
m.InstanceId = types.StringPointerValue(resp.Id)
m.InstanceId = types.StringValue(resp.Id)
m.IsDeletable = types.BoolValue(resp.GetIsDeletable())
m.Name = types.StringValue(resp.GetName())
@ -140,14 +138,14 @@ func mapGetDataInstanceResponseToModel(
return err
}
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
m.RetentionDays = types.Int64Value(resp.GetRetentionDays())
m.Replicas = types.Int32Value(int32(resp.GetReplicas()))
m.RetentionDays = types.Int32Value(resp.GetRetentionDays())
m.Status = types.StringValue(string(resp.GetStatus()))
storage, diags := postgresflexalphadatasource.NewStorageValue(
postgresflexalphadatasource.StorageValue{}.AttributeTypes(ctx),
map[string]attr.Value{
"performance_class": types.StringValue(resp.Storage.GetPerformanceClass()),
"size": types.Int64Value(resp.Storage.GetSize()),
"size": types.Int32Value(resp.Storage.GetSize()),
},
)
if diags.HasError() {
@ -159,9 +157,7 @@ func mapGetDataInstanceResponseToModel(
}
func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) {
isConnectionInfoIncomplete := resp.ConnectionInfo == nil || resp.ConnectionInfo.Write == nil ||
resp.ConnectionInfo.Write.Host == nil || *resp.ConnectionInfo.Write.Host == "" ||
resp.ConnectionInfo.Write.Port == nil || *resp.ConnectionInfo.Write.Port == 0
isConnectionInfoIncomplete := resp.ConnectionInfo.Write.Host == "" || resp.ConnectionInfo.Write.Port == 0
if isConnectionInfoIncomplete {
m.ConnectionInfo = postgresflexalphadatasource.NewConnectionInfoValueNull()
@ -172,8 +168,8 @@ func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgre
"write": types.ObjectValueMust(
postgresflexalphadatasource.WriteValue{}.AttributeTypes(ctx),
map[string]attr.Value{
"host": types.StringPointerValue(resp.ConnectionInfo.Write.Host),
"port": types.Int64PointerValue(resp.ConnectionInfo.Write.Port),
"host": types.StringValue(resp.ConnectionInfo.Write.Host),
"port": types.Int32Value(resp.ConnectionInfo.Write.Port),
},
),
},
@ -189,12 +185,12 @@ func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.G
instAddr := ""
if iA, ok := resp.Network.GetInstanceAddressOk(); ok {
instAddr = iA
instAddr = *iA
}
rtrAddr := ""
if rA, ok := resp.Network.GetRouterAddressOk(); ok {
rtrAddr = rA
rtrAddr = *rA
}
net, diags := postgresflexalphadatasource.NewNetworkValue(
@ -216,22 +212,22 @@ func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.G
func handleEncryption(m *dataSourceModel, resp *postgresflex.GetInstanceResponse) {
keyId := ""
if keyIdVal, ok := resp.Encryption.GetKekKeyIdOk(); ok {
keyId = keyIdVal
keyId = *keyIdVal
}
keyRingId := ""
if keyRingIdVal, ok := resp.Encryption.GetKekKeyRingIdOk(); ok {
keyRingId = keyRingIdVal
keyRingId = *keyRingIdVal
}
keyVersion := ""
if keyVersionVal, ok := resp.Encryption.GetKekKeyVersionOk(); ok {
keyVersion = keyVersionVal
keyVersion = *keyVersionVal
}
svcAcc := ""
if svcAccVal, ok := resp.Encryption.GetServiceAccountOk(); ok {
svcAcc = svcAccVal
svcAcc = *svcAccVal
}
m.Encryption = postgresflexalphadatasource.EncryptionValue{

View file

@ -5,9 +5,9 @@ import (
"testing"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
postgresflexalpharesource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
utils2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
)
@ -17,7 +17,7 @@ func Test_handleConnectionInfo(t *testing.T) {
ctx context.Context
m *dataSourceModel
hostName string
port int64
port int32
}
tests := []struct {
name string
@ -63,10 +63,10 @@ func Test_handleConnectionInfo(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp := &postgresflex.GetInstanceResponse{
ConnectionInfo: &postgresflex.InstanceConnectionInfo{
Write: &postgresflex.InstanceConnectionInfoWrite{
Host: utils.Ptr(tt.args.hostName),
Port: utils.Ptr(tt.args.port),
ConnectionInfo: postgresflex.InstanceConnectionInfo{
Write: postgresflex.InstanceConnectionInfoWrite{
Host: tt.args.hostName,
Port: tt.args.port,
},
},
}
@ -93,7 +93,7 @@ func Test_handleConnectionInfo(t *testing.T) {
if !ok {
t.Errorf("could not find a value for port in connection_info.write")
}
if !gotPort.Equal(types.Int64Value(tt.args.port)) {
if !gotPort.Equal(types.Int32Value(tt.args.port)) {
t.Errorf("port value incorrect: want: %d - got: %s", tt.args.port, gotPort.String())
}
}

View file

@ -4,7 +4,6 @@ import (
"context"
_ "embed"
"fmt"
"math"
"net/http"
"strings"
@ -14,8 +13,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
postgresflex "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/conversion"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
postgresflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
@ -50,7 +49,7 @@ type InstanceResourceIdentityModel struct {
// instanceResource is the resource implementation.
type instanceResource struct {
client *postgresflex.APIClient
client *v3alpha1api.APIClient
providerData core.ProviderData
}
@ -207,15 +206,11 @@ func (r *instanceResource) Create(
return
}
if model.Replicas.ValueInt64() > math.MaxInt32 {
resp.Diagnostics.AddError("invalid int32 value", "provided int64 value does not fit into int32")
return
}
replVal := int32(model.Replicas.ValueInt64()) // nolint:gosec // check is performed above
replVal := model.Replicas.ValueInt32() // nolint:gosec // check is performed above
payload := modelToCreateInstancePayload(netAcl, model, replVal)
// Create new instance
createResp, err := r.client.CreateInstanceRequest(
createResp, err := r.client.DefaultAPI.CreateInstanceRequest(
ctx,
projectId,
region,
@ -236,14 +231,14 @@ func (r *instanceResource) Create(
identity := InstanceResourceIdentityModel{
ProjectID: types.StringValue(projectId),
Region: types.StringValue(region),
InstanceID: types.StringValue(instanceId),
InstanceID: types.StringPointerValue(instanceId),
}
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
if resp.Diagnostics.HasError() {
return
}
waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).
waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, region, *instanceId).
WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(
@ -279,34 +274,32 @@ func modelToCreateInstancePayload(
netAcl []string,
model postgresflexalpha.InstanceModel,
replVal int32,
) postgresflex.CreateInstanceRequestPayload {
var enc *postgresflex.InstanceEncryption
) v3alpha1api.CreateInstanceRequestPayload {
var enc *v3alpha1api.InstanceEncryption
if !model.Encryption.IsNull() && !model.Encryption.IsUnknown() {
enc = &postgresflex.InstanceEncryption{
KekKeyId: model.Encryption.KekKeyId.ValueStringPointer(),
KekKeyRingId: model.Encryption.KekKeyRingId.ValueStringPointer(),
KekKeyVersion: model.Encryption.KekKeyVersion.ValueStringPointer(),
ServiceAccount: model.Encryption.ServiceAccount.ValueStringPointer(),
enc = &v3alpha1api.InstanceEncryption{
KekKeyId: model.Encryption.KekKeyId.ValueString(),
KekKeyRingId: model.Encryption.KekKeyRingId.ValueString(),
KekKeyVersion: model.Encryption.KekKeyVersion.ValueString(),
ServiceAccount: model.Encryption.ServiceAccount.ValueString(),
}
}
payload := postgresflex.CreateInstanceRequestPayload{
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
payload := v3alpha1api.CreateInstanceRequestPayload{
BackupSchedule: model.BackupSchedule.ValueString(),
Encryption: enc,
FlavorId: model.FlavorId.ValueStringPointer(),
Name: model.Name.ValueStringPointer(),
Network: &postgresflex.InstanceNetworkCreate{
AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType(
model.Network.AccessScope.ValueStringPointer(),
),
Acl: &netAcl,
FlavorId: model.FlavorId.ValueString(),
Name: model.Name.ValueString(),
Network: v3alpha1api.InstanceNetworkCreate{
AccessScope: (*v3alpha1api.InstanceNetworkAccessScope)(model.Network.AccessScope.ValueStringPointer()),
Acl: netAcl,
},
Replicas: postgresflex.CreateInstanceRequestPayloadGetReplicasAttributeType(&replVal),
RetentionDays: model.RetentionDays.ValueInt64Pointer(),
Storage: &postgresflex.StorageCreate{
PerformanceClass: model.Storage.PerformanceClass.ValueStringPointer(),
Size: model.Storage.Size.ValueInt64Pointer(),
Replicas: v3alpha1api.Replicas(replVal),
RetentionDays: model.RetentionDays.ValueInt32(),
Storage: v3alpha1api.StorageCreate{
PerformanceClass: model.Storage.PerformanceClass.ValueString(),
Size: model.Storage.Size.ValueInt32(),
},
Version: model.Version.ValueStringPointer(),
Version: model.Version.ValueString(),
}
return payload
}
@ -347,7 +340,7 @@ func (r *instanceResource) Read(
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "region", region)
instanceResp, err := r.client.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
instanceResp, err := r.client.DefaultAPI.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
if err != nil {
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if ok && oapiErr.StatusCode == http.StatusNotFound {
@ -366,7 +359,7 @@ func (r *instanceResource) Read(
return
}
if !model.InstanceId.IsUnknown() && !model.InstanceId.IsNull() {
if respInstanceID != instanceId {
if *respInstanceID != instanceId {
core.LogAndAddError(
ctx,
&resp.Diagnostics,
@ -445,29 +438,24 @@ func (r *instanceResource) Update(
return
}
if model.Replicas.ValueInt64() > math.MaxInt32 {
resp.Diagnostics.AddError("invalid int32 value", "provided int64 value does not fit into int32")
return
}
replInt32 := int32(model.Replicas.ValueInt64()) // nolint:gosec // check is performed above
payload := postgresflex.UpdateInstanceRequestPayload{
BackupSchedule: model.BackupSchedule.ValueStringPointer(),
FlavorId: model.FlavorId.ValueStringPointer(),
Name: model.Name.ValueStringPointer(),
Network: &postgresflex.InstanceNetworkUpdate{
Acl: &netAcl,
replInt32 := model.Replicas.ValueInt32()
payload := v3alpha1api.UpdateInstanceRequestPayload{
BackupSchedule: model.BackupSchedule.ValueString(),
FlavorId: model.FlavorId.ValueString(),
Name: model.Name.ValueString(),
Network: v3alpha1api.InstanceNetworkUpdate{
Acl: netAcl,
},
Replicas: postgresflex.UpdateInstanceRequestPayloadGetReplicasAttributeType(&replInt32),
RetentionDays: model.RetentionDays.ValueInt64Pointer(),
Storage: &postgresflex.StorageUpdate{
Size: model.Storage.Size.ValueInt64Pointer(),
Replicas: v3alpha1api.Replicas(replInt32),
RetentionDays: model.RetentionDays.ValueInt32(),
Storage: v3alpha1api.StorageUpdate{
Size: model.Storage.Size.ValueInt32Pointer(),
},
Version: model.Version.ValueStringPointer(),
Version: model.Version.ValueString(),
}
// Update existing instance
err := r.client.UpdateInstanceRequest(
err := r.client.DefaultAPI.UpdateInstanceRequest(
ctx,
projectId,
region,
@ -482,7 +470,7 @@ func (r *instanceResource) Update(
waitResp, err := wait.PartialUpdateInstanceWaitHandler(
ctx,
r.client,
r.client.DefaultAPI,
projectId,
region,
instanceId,
@ -540,7 +528,7 @@ func (r *instanceResource) Delete(
ctx = tflog.SetField(ctx, "region", region)
// Delete existing instance
err := r.client.DeleteInstanceRequest(ctx, projectId, region, instanceId).Execute()
err := r.client.DefaultAPI.DeleteInstanceRequest(ctx, projectId, region, instanceId).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err))
return
@ -548,7 +536,7 @@ func (r *instanceResource) Delete(
ctx = core.LogResponse(ctx)
_, err = r.client.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
_, err = r.client.DefaultAPI.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
if err != nil {
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if ok && oapiErr.StatusCode != http.StatusNotFound {

View file

@ -5,7 +5,7 @@ package postgresflexalpha
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/int32validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
@ -42,7 +42,7 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema {
Description: "The host of the instance.",
MarkdownDescription: "The host of the instance.",
},
"port": schema.Int64Attribute{
"port": schema.Int32Attribute{
Computed: true,
Description: "The port of the instance.",
MarkdownDescription: "The port of the instance.",
@ -178,18 +178,18 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema {
),
},
},
"replicas": schema.Int64Attribute{
"replicas": schema.Int32Attribute{
Required: true,
Description: "How many replicas the instance should have.",
MarkdownDescription: "How many replicas the instance should have.",
Validators: []validator.Int64{
int64validator.OneOf(
Validators: []validator.Int32{
int32validator.OneOf(
1,
3,
),
},
},
"retention_days": schema.Int64Attribute{
"retention_days": schema.Int32Attribute{
Required: true,
Description: "How long backups are retained. The value can only be between 32 and 365 days.",
MarkdownDescription: "How long backups are retained. The value can only be between 32 and 365 days.",
@ -206,7 +206,7 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema {
Description: "The storage class for the storage.",
MarkdownDescription: "The storage class for the storage.",
},
"size": schema.Int64Attribute{
"size": schema.Int32Attribute{
Required: true,
Description: "The storage size in Gigabytes.",
MarkdownDescription: "The storage size in Gigabytes.",
@ -243,8 +243,8 @@ type InstanceModel struct {
Network NetworkValue `tfsdk:"network"`
ProjectId types.String `tfsdk:"project_id"`
Region types.String `tfsdk:"region"`
Replicas types.Int64 `tfsdk:"replicas"`
RetentionDays types.Int64 `tfsdk:"retention_days"`
Replicas types.Int32 `tfsdk:"replicas"`
RetentionDays types.Int32 `tfsdk:"retention_days"`
Status types.String `tfsdk:"status"`
Storage StorageValue `tfsdk:"storage"`
Version types.String `tfsdk:"version"`
@ -654,12 +654,12 @@ func (t WriteType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue
return nil, diags
}
portVal, ok := portAttribute.(basetypes.Int64Value)
portVal, ok := portAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
fmt.Sprintf(`port expected to be basetypes.Int32Value, was: %T`, portAttribute))
}
if diags.HasError() {
@ -764,12 +764,12 @@ func NewWriteValue(attributeTypes map[string]attr.Type, attributes map[string]at
return NewWriteValueUnknown(), diags
}
portVal, ok := portAttribute.(basetypes.Int64Value)
portVal, ok := portAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute))
fmt.Sprintf(`port expected to be basetypes.Int32Value, was: %T`, portAttribute))
}
if diags.HasError() {
@ -852,7 +852,7 @@ var _ basetypes.ObjectValuable = WriteValue{}
type WriteValue struct {
Host basetypes.StringValue `tfsdk:"host"`
Port basetypes.Int64Value `tfsdk:"port"`
Port basetypes.Int32Value `tfsdk:"port"`
state attr.ValueState
}
@ -863,7 +863,7 @@ func (v WriteValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error)
var err error
attrTypes["host"] = basetypes.StringType{}.TerraformType(ctx)
attrTypes["port"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["port"] = basetypes.Int32Type{}.TerraformType(ctx)
objectType := tftypes.Object{AttributeTypes: attrTypes}
@ -918,7 +918,7 @@ func (v WriteValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, d
attributeTypes := map[string]attr.Type{
"host": basetypes.StringType{},
"port": basetypes.Int64Type{},
"port": basetypes.Int32Type{},
}
if v.IsNull() {
@ -976,7 +976,7 @@ func (v WriteValue) Type(ctx context.Context) attr.Type {
func (v WriteValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
return map[string]attr.Type{
"host": basetypes.StringType{},
"port": basetypes.Int64Type{},
"port": basetypes.Int32Type{},
}
}
@ -2040,12 +2040,12 @@ func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectVal
return nil, diags
}
sizeVal, ok := sizeAttribute.(basetypes.Int64Value)
sizeVal, ok := sizeAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute))
fmt.Sprintf(`size expected to be basetypes.Int32Value, was: %T`, sizeAttribute))
}
if diags.HasError() {
@ -2150,12 +2150,12 @@ func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]
return NewStorageValueUnknown(), diags
}
sizeVal, ok := sizeAttribute.(basetypes.Int64Value)
sizeVal, ok := sizeAttribute.(basetypes.Int32Value)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute))
fmt.Sprintf(`size expected to be basetypes.Int32Value, was: %T`, sizeAttribute))
}
if diags.HasError() {
@ -2238,7 +2238,7 @@ var _ basetypes.ObjectValuable = StorageValue{}
type StorageValue struct {
PerformanceClass basetypes.StringValue `tfsdk:"performance_class"`
Size basetypes.Int64Value `tfsdk:"size"`
Size basetypes.Int32Value `tfsdk:"size"`
state attr.ValueState
}
@ -2249,7 +2249,7 @@ func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, erro
var err error
attrTypes["performance_class"] = basetypes.StringType{}.TerraformType(ctx)
attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx)
attrTypes["size"] = basetypes.Int32Type{}.TerraformType(ctx)
objectType := tftypes.Object{AttributeTypes: attrTypes}
@ -2304,7 +2304,7 @@ func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue,
attributeTypes := map[string]attr.Type{
"performance_class": basetypes.StringType{},
"size": basetypes.Int64Type{},
"size": basetypes.Int32Type{},
}
if v.IsNull() {
@ -2362,6 +2362,6 @@ func (v StorageValue) Type(ctx context.Context) attr.Type {
func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type {
return map[string]attr.Type{
"performance_class": basetypes.StringType{},
"size": basetypes.Int64Type{},
"size": basetypes.Int32Type{},
}
}