@@ -29,8 +29,8 @@ import (
2929 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
3030 "github.com/hashicorp/terraform-plugin-framework/types"
3131 "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
32- "github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
33- "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
32+ postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api "
33+ "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/ wait"
3434)
3535
3636// Ensure the implementation satisfies the expected interfaces.
@@ -49,7 +49,7 @@ type Model struct {
4949 ACL types.List `tfsdk:"acl"`
5050 BackupSchedule types.String `tfsdk:"backup_schedule"`
5151 Flavor types.Object `tfsdk:"flavor"`
52- Replicas types.Int64 `tfsdk:"replicas"`
52+ Replicas types.Int32 `tfsdk:"replicas"`
5353 Storage types.Object `tfsdk:"storage"`
5454 Version types.String `tfsdk:"version"`
5555 Region types.String `tfsdk:"region"`
@@ -238,7 +238,7 @@ func (r *instanceResource) Schema(_ context.Context, req resource.SchemaRequest,
238238 },
239239 },
240240 },
241- "replicas" : schema.Int64Attribute {
241+ "replicas" : schema.Int32Attribute {
242242 Description : descriptions ["replicas" ],
243243 Required : true ,
244244 },
@@ -304,7 +304,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
304304 if resp .Diagnostics .HasError () {
305305 return
306306 }
307- err := loadFlavorId (ctx , r .client , & model , flavor )
307+ err := loadFlavorId (ctx , r .client . DefaultAPI , & model , flavor )
308308 if err != nil {
309309 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Loading flavor ID: %v" , err ))
310310 return
@@ -326,7 +326,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
326326 return
327327 }
328328 // Create new instance
329- createResp , err := r .client .CreateInstance (ctx , projectId , region ).CreateInstancePayload (* payload ).Execute ()
329+ createResp , err := r .client .DefaultAPI . CreateInstance (ctx , projectId , region ).CreateInstancePayload (* payload ).Execute ()
330330 if err != nil {
331331 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Calling API: %v" , err ))
332332 return
@@ -349,7 +349,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
349349 return
350350 }
351351
352- waitResp , err := wait .CreateInstanceWaitHandler (ctx , r .client , projectId , region , instanceId ).WaitWithContext (ctx )
352+ waitResp , err := wait .CreateInstanceWaitHandler (ctx , r .client . DefaultAPI , projectId , region , instanceId ).WaitWithContext (ctx )
353353 if err != nil {
354354 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
355355 return
@@ -405,7 +405,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
405405 }
406406 }
407407
408- instanceResp , err := r .client .GetInstance (ctx , projectId , region , instanceId ).Execute ()
408+ instanceResp , err := r .client .DefaultAPI . GetInstance (ctx , projectId , region , instanceId ).Execute ()
409409 if err != nil {
410410 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
411411 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -472,7 +472,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
472472 if resp .Diagnostics .HasError () {
473473 return
474474 }
475- err := loadFlavorId (ctx , r .client , & model , flavor )
475+ err := loadFlavorId (ctx , r .client . DefaultAPI , & model , flavor )
476476 if err != nil {
477477 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , fmt .Sprintf ("Loading flavor ID: %v" , err ))
478478 return
@@ -494,15 +494,15 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
494494 return
495495 }
496496 // Update existing instance
497- _ , err = r .client .PartialUpdateInstance (ctx , projectId , region , instanceId ).PartialUpdateInstancePayload (* payload ).Execute ()
497+ _ , err = r .client .DefaultAPI . PartialUpdateInstance (ctx , projectId , region , instanceId ).PartialUpdateInstancePayload (* payload ).Execute ()
498498 if err != nil {
499499 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , err .Error ())
500500 return
501501 }
502502
503503 ctx = core .LogResponse (ctx )
504504
505- waitResp , err := wait .PartialUpdateInstanceWaitHandler (ctx , r .client , projectId , region , instanceId ).WaitWithContext (ctx )
505+ waitResp , err := wait .PartialUpdateInstanceWaitHandler (ctx , r .client . DefaultAPI , projectId , region , instanceId ).WaitWithContext (ctx )
506506 if err != nil {
507507 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , fmt .Sprintf ("Instance update waiting: %v" , err ))
508508 return
@@ -542,15 +542,15 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
542542 ctx = tflog .SetField (ctx , "region" , region )
543543
544544 // Delete existing instance
545- err := r .client .DeleteInstance (ctx , projectId , region , instanceId ).Execute ()
545+ err := r .client .DefaultAPI . DeleteInstance (ctx , projectId , region , instanceId ).Execute ()
546546 if err != nil {
547547 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting instance" , fmt .Sprintf ("Calling API: %v" , err ))
548548 return
549549 }
550550
551551 ctx = core .LogResponse (ctx )
552552
553- _ , err = wait .DeleteInstanceWaitHandler (ctx , r .client , projectId , region , instanceId ).SetTimeout (45 * time .Minute ).WaitWithContext (ctx )
553+ _ , err = wait .DeleteInstanceWaitHandler (ctx , r .client . DefaultAPI , projectId , region , instanceId ).SetTimeout (45 * time .Minute ).WaitWithContext (ctx )
554554 if err != nil {
555555 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting instance" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
556556 return
@@ -605,7 +605,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *
605605 if instance .Acl == nil || instance .Acl .Items == nil {
606606 aclList = types .ListNull (types .StringType )
607607 } else {
608- respACL := * instance .Acl .Items
608+ respACL := instance .Acl .Items
609609 modelACL , err := utils .ListValuetoStringSlice (model .ACL )
610610 if err != nil {
611611 return err
@@ -670,7 +670,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *
670670 model .Name = types .StringPointerValue (instance .Name )
671671 model .ACL = aclList
672672 model .Flavor = flavorObject
673- model .Replicas = types .Int64PointerValue (instance .Replicas )
673+ model .Replicas = types .Int32PointerValue (instance .Replicas )
674674 model .Storage = storageObject
675675 model .Version = types .StringPointerValue (instance .Version )
676676 model .Region = types .StringValue (region )
@@ -692,18 +692,18 @@ func toCreatePayload(model *Model, acl []string, flavor *flavorModel, storage *s
692692 }
693693
694694 return & postgresflex.CreateInstancePayload {
695- Acl : & postgresflex.ACL {
696- Items : & acl ,
695+ Acl : postgresflex.ACL {
696+ Items : acl ,
697697 },
698- BackupSchedule : conversion . StringValueToPointer ( model .BackupSchedule ),
699- FlavorId : conversion . StringValueToPointer ( flavor .Id ),
700- Name : conversion . StringValueToPointer ( model .Name ),
701- Replicas : conversion . Int64ValueToPointer ( model .Replicas ),
702- Storage : & postgresflex.Storage {
698+ BackupSchedule : model .BackupSchedule . ValueString ( ),
699+ FlavorId : flavor .Id . ValueString ( ),
700+ Name : model .Name . ValueString ( ),
701+ Replicas : model .Replicas . ValueInt32 ( ),
702+ Storage : postgresflex.Storage {
703703 Class : conversion .StringValueToPointer (storage .Class ),
704704 Size : conversion .Int64ValueToPointer (storage .Size ),
705705 },
706- Version : conversion . StringValueToPointer ( model .Version ),
706+ Version : model .Version . ValueString ( ),
707707 }, nil
708708}
709709
@@ -723,18 +723,19 @@ func toUpdatePayload(model *Model, acl []string, flavor *flavorModel, storage *s
723723
724724 return & postgresflex.PartialUpdateInstancePayload {
725725 Acl : & postgresflex.ACL {
726- Items : & acl ,
726+ Items : acl ,
727727 },
728728 BackupSchedule : conversion .StringValueToPointer (model .BackupSchedule ),
729729 FlavorId : conversion .StringValueToPointer (flavor .Id ),
730730 Name : conversion .StringValueToPointer (model .Name ),
731- Replicas : conversion .Int64ValueToPointer (model .Replicas ),
731+ Replicas : conversion .Int32ValueToPointer (model .Replicas ),
732732 Version : conversion .StringValueToPointer (model .Version ),
733733 }, nil
734734}
735735
736736type postgresFlexClient interface {
737- ListFlavorsExecute (ctx context.Context , projectId string , region string ) (* postgresflex.ListFlavorsResponse , error )
737+ ListFlavors (ctx context.Context , projectId , region string ) postgresflex.ApiListFlavorsRequest
738+ ListFlavorsExecute (r postgresflex.ApiListFlavorsRequest ) (* postgresflex.ListFlavorsResponse , error )
738739}
739740
740741func loadFlavorId (ctx context.Context , client postgresFlexClient , model * Model , flavor * flavorModel ) error {
@@ -755,7 +756,8 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model,
755756
756757 projectId := model .ProjectId .ValueString ()
757758 region := model .Region .ValueString ()
758- res , err := client .ListFlavorsExecute (ctx , projectId , region )
759+ req := client .ListFlavors (ctx , projectId , region )
760+ res , err := client .ListFlavorsExecute (req )
759761 if err != nil {
760762 return fmt .Errorf ("listing postgresflex flavors: %w" , err )
761763 }
@@ -764,7 +766,7 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model,
764766 if res .Flavors == nil {
765767 return fmt .Errorf ("finding flavors for project %s" , projectId )
766768 }
767- for _ , f := range * res .Flavors {
769+ for _ , f := range res .Flavors {
768770 if f .Id == nil || f .Cpu == nil || f .Memory == nil {
769771 continue
770772 }
0 commit comments