@@ -28,8 +28,8 @@ import (
2828 "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2929 "github.com/hashicorp/terraform-plugin-framework/types"
3030 "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
31- "github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
32- "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
31+ postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api "
32+ "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/ wait"
3333)
3434
3535// Ensure the implementation satisfies the expected interfaces.
@@ -48,7 +48,7 @@ type Model struct {
4848 ACL types.List `tfsdk:"acl"`
4949 BackupSchedule types.String `tfsdk:"backup_schedule"`
5050 Flavor types.Object `tfsdk:"flavor"`
51- Replicas types.Int64 `tfsdk:"replicas"`
51+ Replicas types.Int32 `tfsdk:"replicas"`
5252 Storage types.Object `tfsdk:"storage"`
5353 Version types.String `tfsdk:"version"`
5454 Region types.String `tfsdk:"region"`
@@ -237,7 +237,7 @@ func (r *instanceResource) Schema(_ context.Context, req resource.SchemaRequest,
237237 },
238238 },
239239 },
240- "replicas" : schema.Int64Attribute {
240+ "replicas" : schema.Int32Attribute {
241241 Description : descriptions ["replicas" ],
242242 Required : true ,
243243 },
@@ -303,7 +303,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
303303 if resp .Diagnostics .HasError () {
304304 return
305305 }
306- err := loadFlavorId (ctx , r .client , & model , flavor )
306+ err := loadFlavorId (ctx , r .client . DefaultAPI , & model , flavor )
307307 if err != nil {
308308 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Loading flavor ID: %v" , err ))
309309 return
@@ -325,7 +325,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
325325 return
326326 }
327327 // Create new instance
328- createResp , err := r .client .CreateInstance (ctx , projectId , region ).CreateInstancePayload (* payload ).Execute ()
328+ createResp , err := r .client .DefaultAPI . CreateInstance (ctx , projectId , region ).CreateInstancePayload (* payload ).Execute ()
329329 if err != nil {
330330 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Calling API: %v" , err ))
331331 return
@@ -348,7 +348,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
348348 return
349349 }
350350
351- waitResp , err := wait .CreateInstanceWaitHandler (ctx , r .client , projectId , region , instanceId ).WaitWithContext (ctx )
351+ waitResp , err := wait .CreateInstanceWaitHandler (ctx , r .client . DefaultAPI , projectId , region , instanceId ).WaitWithContext (ctx )
352352 if err != nil {
353353 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating instance" , fmt .Sprintf ("Instance creation waiting: %v" , err ))
354354 return
@@ -404,7 +404,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
404404 }
405405 }
406406
407- instanceResp , err := r .client .GetInstance (ctx , projectId , region , instanceId ).Execute ()
407+ instanceResp , err := r .client .DefaultAPI . GetInstance (ctx , projectId , region , instanceId ).Execute ()
408408 if err != nil {
409409 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
410410 if ok && oapiErr .StatusCode == http .StatusNotFound {
@@ -471,7 +471,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
471471 if resp .Diagnostics .HasError () {
472472 return
473473 }
474- err := loadFlavorId (ctx , r .client , & model , flavor )
474+ err := loadFlavorId (ctx , r .client . DefaultAPI , & model , flavor )
475475 if err != nil {
476476 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , fmt .Sprintf ("Loading flavor ID: %v" , err ))
477477 return
@@ -493,15 +493,15 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
493493 return
494494 }
495495 // Update existing instance
496- _ , err = r .client .PartialUpdateInstance (ctx , projectId , region , instanceId ).PartialUpdateInstancePayload (* payload ).Execute ()
496+ _ , err = r .client .DefaultAPI . PartialUpdateInstance (ctx , projectId , region , instanceId ).PartialUpdateInstancePayload (* payload ).Execute ()
497497 if err != nil {
498498 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , err .Error ())
499499 return
500500 }
501501
502502 ctx = core .LogResponse (ctx )
503503
504- waitResp , err := wait .PartialUpdateInstanceWaitHandler (ctx , r .client , projectId , region , instanceId ).WaitWithContext (ctx )
504+ waitResp , err := wait .PartialUpdateInstanceWaitHandler (ctx , r .client . DefaultAPI , projectId , region , instanceId ).WaitWithContext (ctx )
505505 if err != nil {
506506 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating instance" , fmt .Sprintf ("Instance update waiting: %v" , err ))
507507 return
@@ -541,15 +541,15 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
541541 ctx = tflog .SetField (ctx , "region" , region )
542542
543543 // Delete existing instance
544- err := r .client .DeleteInstance (ctx , projectId , region , instanceId ).Execute ()
544+ err := r .client .DefaultAPI . DeleteInstance (ctx , projectId , region , instanceId ).Execute ()
545545 if err != nil {
546546 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting instance" , fmt .Sprintf ("Calling API: %v" , err ))
547547 return
548548 }
549549
550550 ctx = core .LogResponse (ctx )
551551
552- _ , err = wait .DeleteInstanceWaitHandler (ctx , r .client , projectId , region , instanceId ).SetTimeout (45 * time .Minute ).WaitWithContext (ctx )
552+ _ , err = wait .DeleteInstanceWaitHandler (ctx , r .client . DefaultAPI , projectId , region , instanceId ).SetTimeout (45 * time .Minute ).WaitWithContext (ctx )
553553 if err != nil {
554554 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting instance" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
555555 return
@@ -604,7 +604,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *
604604 if instance .Acl == nil || instance .Acl .Items == nil {
605605 aclList = types .ListNull (types .StringType )
606606 } else {
607- respACL := * instance .Acl .Items
607+ respACL := instance .Acl .Items
608608 modelACL , err := utils .ListValuetoStringSlice (model .ACL )
609609 if err != nil {
610610 return err
@@ -669,7 +669,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *
669669 model .Name = types .StringPointerValue (instance .Name )
670670 model .ACL = aclList
671671 model .Flavor = flavorObject
672- model .Replicas = types .Int64PointerValue (instance .Replicas )
672+ model .Replicas = types .Int32PointerValue (instance .Replicas )
673673 model .Storage = storageObject
674674 model .Version = types .StringPointerValue (instance .Version )
675675 model .Region = types .StringValue (region )
@@ -691,18 +691,18 @@ func toCreatePayload(model *Model, acl []string, flavor *flavorModel, storage *s
691691 }
692692
693693 return & postgresflex.CreateInstancePayload {
694- Acl : & postgresflex.ACL {
695- Items : & acl ,
694+ Acl : postgresflex.ACL {
695+ Items : acl ,
696696 },
697- BackupSchedule : conversion . StringValueToPointer ( model .BackupSchedule ),
698- FlavorId : conversion . StringValueToPointer ( flavor .Id ),
699- Name : conversion . StringValueToPointer ( model .Name ),
700- Replicas : conversion . Int64ValueToPointer ( model .Replicas ),
701- Storage : & postgresflex.Storage {
697+ BackupSchedule : model .BackupSchedule . ValueString ( ),
698+ FlavorId : flavor .Id . ValueString ( ),
699+ Name : model .Name . ValueString ( ),
700+ Replicas : model .Replicas . ValueInt32 ( ),
701+ Storage : postgresflex.Storage {
702702 Class : conversion .StringValueToPointer (storage .Class ),
703703 Size : conversion .Int64ValueToPointer (storage .Size ),
704704 },
705- Version : conversion . StringValueToPointer ( model .Version ),
705+ Version : model .Version . ValueString ( ),
706706 }, nil
707707}
708708
@@ -722,18 +722,19 @@ func toUpdatePayload(model *Model, acl []string, flavor *flavorModel, storage *s
722722
723723 return & postgresflex.PartialUpdateInstancePayload {
724724 Acl : & postgresflex.ACL {
725- Items : & acl ,
725+ Items : acl ,
726726 },
727727 BackupSchedule : conversion .StringValueToPointer (model .BackupSchedule ),
728728 FlavorId : conversion .StringValueToPointer (flavor .Id ),
729729 Name : conversion .StringValueToPointer (model .Name ),
730- Replicas : conversion .Int64ValueToPointer (model .Replicas ),
730+ Replicas : conversion .Int32ValueToPointer (model .Replicas ),
731731 Version : conversion .StringValueToPointer (model .Version ),
732732 }, nil
733733}
734734
735735type postgresFlexClient interface {
736- ListFlavorsExecute (ctx context.Context , projectId string , region string ) (* postgresflex.ListFlavorsResponse , error )
736+ ListFlavors (ctx context.Context , projectId , region string ) postgresflex.ApiListFlavorsRequest
737+ ListFlavorsExecute (r postgresflex.ApiListFlavorsRequest ) (* postgresflex.ListFlavorsResponse , error )
737738}
738739
739740func loadFlavorId (ctx context.Context , client postgresFlexClient , model * Model , flavor * flavorModel ) error {
@@ -754,7 +755,8 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model,
754755
755756 projectId := model .ProjectId .ValueString ()
756757 region := model .Region .ValueString ()
757- res , err := client .ListFlavorsExecute (ctx , projectId , region )
758+ req := client .ListFlavors (ctx , projectId , region )
759+ res , err := client .ListFlavorsExecute (req )
758760 if err != nil {
759761 return fmt .Errorf ("listing postgresflex flavors: %w" , err )
760762 }
@@ -763,7 +765,7 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model,
763765 if res .Flavors == nil {
764766 return fmt .Errorf ("finding flavors for project %s" , projectId )
765767 }
766- for _ , f := range * res .Flavors {
768+ for _ , f := range res .Flavors {
767769 if f .Id == nil || f .Cpu == nil || f .Memory == nil {
768770 continue
769771 }
0 commit comments