From 32b83a08368956a2c01600031e2923bae722310e Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Fri, 30 Jan 2026 11:37:09 +0100 Subject: [PATCH 1/2] fix: refactor postgres genereated files --- .../datasources_gen/instance_data_source_gen.go | 11 +++++++++-- .../instance/resources_gen/instance_resource_gen.go | 13 +++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go b/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go index 3156dccc..5ff386fe 100644 --- a/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go +++ b/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go @@ -20,6 +20,12 @@ import ( func InstanceDataSourceSchema(ctx context.Context) schema.Schema { return schema.Schema{ Attributes: map[string]schema.Attribute{ + "acl": schema.ListAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "List of IPV4 cidr.", + MarkdownDescription: "List of IPV4 cidr.", + }, "backup_schedule": schema.StringAttribute{ Computed: true, Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", @@ -74,8 +80,8 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema { }, }, Computed: true, - Description: "The configuration for instance's volume and backup storage encryption.\n\n⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", - MarkdownDescription: "The configuration for instance's volume and backup storage encryption.\n\n⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", + Description: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", + MarkdownDescription: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", }, "flavor_id": schema.StringAttribute{ Computed: true, @@ -193,6 +199,7 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema { } type InstanceModel struct { + Acl types.List `tfsdk:"acl"` BackupSchedule types.String `tfsdk:"backup_schedule"` ConnectionInfo ConnectionInfoValue `tfsdk:"connection_info"` Encryption EncryptionValue `tfsdk:"encryption"` diff --git a/stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go b/stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go index 3d3f9459..35d31cbc 100644 --- a/stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go +++ b/stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go @@ -22,6 +22,12 @@ import ( func InstanceResourceSchema(ctx context.Context) schema.Schema { return schema.Schema{ Attributes: map[string]schema.Attribute{ + "acl": schema.ListAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "List of IPV4 cidr.", + MarkdownDescription: "List of IPV4 cidr.", + }, "backup_schedule": schema.StringAttribute{ Required: true, Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", @@ -77,8 +83,8 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema { }, Optional: true, Computed: true, - Description: "The configuration for instance's volume and backup storage encryption.\n\n⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", - MarkdownDescription: "The configuration for instance's volume and backup storage encryption.\n\n⚠️ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", + Description: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", + MarkdownDescription: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected.\n", }, "flavor_id": schema.StringAttribute{ Required: true, @@ -128,11 +134,9 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema { MarkdownDescription: "List of IPV4 cidr.", }, "instance_address": schema.StringAttribute{ - Optional: true, Computed: true, }, "router_address": schema.StringAttribute{ - Optional: true, Computed: true, }, }, @@ -215,6 +219,7 @@ func InstanceResourceSchema(ctx context.Context) schema.Schema { } type InstanceModel struct { + Acl types.List `tfsdk:"acl"` BackupSchedule types.String `tfsdk:"backup_schedule"` ConnectionInfo ConnectionInfoValue `tfsdk:"connection_info"` Encryption EncryptionValue `tfsdk:"encryption"` -- 2.49.1 From 764978db88eae8832a150f0d3f2f3b00c6bc564a Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Fri, 30 Jan 2026 11:58:26 +0100 Subject: [PATCH 2/2] fix: refactor postgres after api updates --- .../postgresflexalpha/database/functions.go | 2 +- .../postgresflexalpha/database/resource.go | 17 ++++++++++-- .../postgresflexalpha/flavor/functions.go | 2 +- .../postgresflexalpha/instance/resource.go | 11 +++----- .../postgresflexalpha/user/datasource.go | 9 ++++++- .../postgresflexalpha/user/resource.go | 27 ++++++++++++++++--- 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/stackit/internal/services/postgresflexalpha/database/functions.go b/stackit/internal/services/postgresflexalpha/database/functions.go index 0a1b0369..0355c744 100644 --- a/stackit/internal/services/postgresflexalpha/database/functions.go +++ b/stackit/internal/services/postgresflexalpha/database/functions.go @@ -56,7 +56,7 @@ func getDatabase( const pageSize = 25 - for page := int64(1); ; page++ { + for page := int32(1); ; page++ { res, err := client.ListDatabasesRequest(ctx, projectId, region, instanceId). Page(page).Size(pageSize).Sort(postgresflex.DATABASESORT_INDEX_ASC).Execute() if err != nil { diff --git a/stackit/internal/services/postgresflexalpha/database/resource.go b/stackit/internal/services/postgresflexalpha/database/resource.go index ca851151..ca22d5d0 100644 --- a/stackit/internal/services/postgresflexalpha/database/resource.go +++ b/stackit/internal/services/postgresflexalpha/database/resource.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math" "net/http" "regexp" "strconv" @@ -365,7 +366,13 @@ func (r *databaseResource) Update( projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - databaseId := model.DatabaseId.ValueInt64() + databaseId64 := model.DatabaseId.ValueInt64() + if databaseId64 > math.MaxInt32 { + core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)") + return + } + databaseId := int32(databaseId64) + region := model.Region.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) @@ -449,7 +456,13 @@ func (r *databaseResource) Delete( projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - databaseId := model.DatabaseId.ValueInt64() + databaseId64 := model.DatabaseId.ValueInt64() + + if databaseId64 > math.MaxInt32 { + core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (databaseId)") + return + } + databaseId := int32(databaseId64) region := model.Region.ValueString() ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) diff --git a/stackit/internal/services/postgresflexalpha/flavor/functions.go b/stackit/internal/services/postgresflexalpha/flavor/functions.go index 407dc57d..e65598c1 100644 --- a/stackit/internal/services/postgresflexalpha/flavor/functions.go +++ b/stackit/internal/services/postgresflexalpha/flavor/functions.go @@ -42,7 +42,7 @@ func getFlavorsByFilter( var result = make([]postgresflex.ListFlavors, 0) - for page := int64(1); ; page++ { + for page := int32(1); ; page++ { res, err := client.GetFlavorsRequest(ctx, projectId, region). Page(page).Size(pageSize).Sort(postgresflex.FLAVORSORT_INDEX_ASC).Execute() if err != nil { diff --git a/stackit/internal/services/postgresflexalpha/instance/resource.go b/stackit/internal/services/postgresflexalpha/instance/resource.go index 68c613aa..bc679f0d 100644 --- a/stackit/internal/services/postgresflexalpha/instance/resource.go +++ b/stackit/internal/services/postgresflexalpha/instance/resource.go @@ -261,13 +261,11 @@ func modelToCreateInstancePayload(netAcl []string, model postgresflexalpha.Insta Encryption: &enc, FlavorId: model.FlavorId.ValueStringPointer(), Name: model.Name.ValueStringPointer(), - Network: &postgresflex.InstanceNetwork{ + Network: &postgresflex.InstanceNetworkCreate{ AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType( model.Network.AccessScope.ValueStringPointer(), ), - Acl: &netAcl, - InstanceAddress: model.Network.InstanceAddress.ValueStringPointer(), - RouterAddress: model.Network.RouterAddress.ValueStringPointer(), + Acl: &netAcl, }, Replicas: postgresflex.CreateInstanceRequestPayloadGetReplicasAttributeType(&replVal), RetentionDays: model.RetentionDays.ValueInt64Pointer(), @@ -452,10 +450,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques BackupSchedule: model.BackupSchedule.ValueStringPointer(), FlavorId: model.FlavorId.ValueStringPointer(), Name: model.Name.ValueStringPointer(), - Network: &postgresflex.InstanceNetwork{ - AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType( - model.Network.AccessScope.ValueStringPointer(), - ), + Network: &postgresflex.InstanceNetworkUpdate{ Acl: &netAcl, }, Replicas: postgresflex.UpdateInstanceRequestPayloadGetReplicasAttributeType(&replInt32), diff --git a/stackit/internal/services/postgresflexalpha/user/datasource.go b/stackit/internal/services/postgresflexalpha/user/datasource.go index 86ed10a4..ec351e4b 100644 --- a/stackit/internal/services/postgresflexalpha/user/datasource.go +++ b/stackit/internal/services/postgresflexalpha/user/datasource.go @@ -3,6 +3,7 @@ package postgresflexalpha import ( "context" "fmt" + "math" "net/http" "strconv" @@ -179,7 +180,13 @@ func (r *userDataSource) Read( projectId := model.ProjectId.ValueString() instanceId := model.InstanceId.ValueString() - userId := model.UserId.ValueInt64() + userId64 := model.UserId.ValueInt64() + if userId64 > math.MaxInt32 { + core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)") + return + } + userId := int32(userId64) + region := r.providerData.GetRegionWithOverride(model.Region) ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) diff --git a/stackit/internal/services/postgresflexalpha/user/resource.go b/stackit/internal/services/postgresflexalpha/user/resource.go index c213d6e0..e01899ba 100644 --- a/stackit/internal/services/postgresflexalpha/user/resource.go +++ b/stackit/internal/services/postgresflexalpha/user/resource.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "math" "net/http" "strconv" "strings" @@ -390,13 +391,20 @@ func (r *userResource) Update( return } + userId64 := arg.userId + if userId64 > math.MaxInt32 { + core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)") + return + } + userId := int32(userId64) + // Update existing instance err = r.client.UpdateUserRequest( ctx, arg.projectId, arg.region, arg.instanceId, - arg.userId, + userId, ).UpdateUserRequestPayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", err.Error()) @@ -446,8 +454,15 @@ func (r *userResource) Delete( ctx = r.setTFLogFields(ctx, &model) arg := r.getClientArg(&model) + userId64 := arg.userId + if userId64 > math.MaxInt32 { + core.LogAndAddError(ctx, &resp.Diagnostics, "Error in type conversion", "int value too large (userId)") + return + } + userId := int32(userId64) + // Delete existing record set - err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, arg.userId).Execute() + err := r.client.DeleteUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err)) } @@ -555,8 +570,14 @@ func (r *userResource) getUserResource(ctx context.Context, model *Model) (bool, ctx = r.setTFLogFields(ctx, model) arg := r.getClientArg(model) + userId64 := arg.userId + if userId64 > math.MaxInt32 { + return false, errors.New("error in type conversion: int value too large (userId)") + } + userId := int32(userId64) + // API Call - userResp, err := r.client.GetUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, arg.userId).Execute() + userResp, err := r.client.GetUserRequest(ctx, arg.projectId, arg.region, arg.instanceId, userId).Execute() if err != nil { var oapiErr *oapierror.GenericOpenAPIError -- 2.49.1