diff --git a/go.mod b/go.mod index 3ad37b5e4..c512153c2 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/cdn v1.14.0 github.com/stackitcloud/stackit-sdk-go/services/certificates v1.4.1 github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1 - github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0 + github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.1 github.com/stackitcloud/stackit-sdk-go/services/git v0.11.0 github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 github.com/stackitcloud/stackit-sdk-go/services/kms v1.6.0 @@ -30,7 +30,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0 github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0 github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1 - github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 + github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.6.2 github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.29.0 github.com/stackitcloud/stackit-sdk-go/services/redis v0.28.1 github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0 diff --git a/go.sum b/go.sum index 999175d98..00b95d6e7 100644 --- a/go.sum +++ b/go.sum @@ -682,6 +682,8 @@ github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1 h1:VfszhFq/Snsd0Lnfl github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1/go.mod h1:gBv6YkB3Xf3c0ZXg2GwtWY8zExwGPF/Ag114XiiERxg= github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0 h1:lsOTEvItzrUerCzUodyyOy6pZ4QiSzwID7U20ZvZvHw= github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0/go.mod h1:CfqSEGCW0b5JlijCwtUT1kfjThmQ5jXX47TWrdD5rTU= +github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.1 h1:G21hx6vztR1Np+K+MXsK1td/CKbKHdLK89zvtH6OoKk= +github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.1/go.mod h1:qHuMB/qt7w1u5Xk3qzP3pJFXjTqPrtpM2bMhKpIvM3I= github.com/stackitcloud/stackit-sdk-go/services/git v0.11.0 h1:siKBCYl7BwR5S25Y4SwUAX6eFTXSCkQ+8JIQEqyKIXo= github.com/stackitcloud/stackit-sdk-go/services/git v0.11.0/go.mod h1:QKy74hhLVZKXItw3y+elF8s9QezFqpEsAUmaqvNDzYs= github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 h1:W57+XRa8wTLsi5CV9Tqa7mGgt/PvlRM//RurXSmvII8= @@ -708,6 +710,8 @@ github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1 h1:AO5Np67/w0 github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1/go.mod h1:Reo2Nk3yiA686quUMrk0eKwzpzaAZ7KwmzHzScNdG8Q= github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 h1:H67e3KnHQx954yI8fuQmxXwRf/myqAdLg2KvxImp00g= github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5/go.mod h1:xmAWk9eom8wznvLuLfm0F4xyeiBX8LaggXsKFmos+dw= +github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.6.2 h1:5Op07pEs6dcJxfi2UjT1645k1uMf1xMbY8/D3A797aA= +github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.6.2/go.mod h1:AqFWa9kddt2Wqe8k1Kw5FB1mlHG30K1FGsJx8dw/r1c= github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.29.0 h1:I8NF8Q5nRj7/7qDI8Qm4oI0KCNQcOjE6kqyBdWcUoxk= github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.29.0/go.mod h1:wk2Oz+7pxT9YF1h6elWzdlhU6V7GSQXcGixxlXxNe+U= github.com/stackitcloud/stackit-sdk-go/services/redis v0.28.1 h1:6loJq37rLpU84HY/rzmpZrBGPz2vKqhly8mUC8NcAu0= diff --git a/stackit/internal/services/postgresflex/database/datasource.go b/stackit/internal/services/postgresflex/database/datasource.go index 62232ea02..15fc5a831 100644 --- a/stackit/internal/services/postgresflex/database/datasource.go +++ b/stackit/internal/services/postgresflex/database/datasource.go @@ -17,7 +17,7 @@ import ( "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" ) // Ensure the implementation satisfies the expected interfaces. diff --git a/stackit/internal/services/postgresflex/database/resource.go b/stackit/internal/services/postgresflex/database/resource.go index 3d958f855..ba0d2d5bc 100644 --- a/stackit/internal/services/postgresflex/database/resource.go +++ b/stackit/internal/services/postgresflex/database/resource.go @@ -23,7 +23,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -215,7 +215,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques return } // Create new database - databaseResp, err := r.client.CreateDatabase(ctx, projectId, region, instanceId).CreateDatabasePayload(*payload).Execute() + databaseResp, err := r.client.DefaultAPI.CreateDatabase(ctx, projectId, region, instanceId).CreateDatabasePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating database", fmt.Sprintf("Calling API: %v", err)) return @@ -328,7 +328,7 @@ func (r *databaseResource) Delete(ctx context.Context, req resource.DeleteReques ctx = tflog.SetField(ctx, "region", region) // Delete existing record set - err := r.client.DeleteDatabase(ctx, projectId, region, instanceId, databaseId).Execute() + err := r.client.DefaultAPI.DeleteDatabase(ctx, projectId, region, instanceId, databaseId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting database", fmt.Sprintf("Calling API: %v", err)) } @@ -390,7 +390,7 @@ func mapFields(databaseResp *postgresflex.InstanceDatabase, model *Model, region model.Region = types.StringValue(region) if databaseResp.Options != nil { - owner, ok := (*databaseResp.Options)["owner"] + owner, ok := (databaseResp.Options)["owner"] if ok { ownerStr, ok := owner.(string) if !ok { @@ -423,14 +423,14 @@ var errDatabaseNotFound = errors.New("database not found") // The API does not have a GetDatabase endpoint, only ListDatabases func getDatabase(ctx context.Context, client *postgresflex.APIClient, projectId, region, instanceId, databaseId string) (*postgresflex.InstanceDatabase, error) { - resp, err := client.ListDatabases(ctx, projectId, region, instanceId).Execute() + resp, err := client.DefaultAPI.ListDatabases(ctx, projectId, region, instanceId).Execute() if err != nil { return nil, err } if resp == nil || resp.Databases == nil { return nil, fmt.Errorf("response is nil") } - for _, database := range *resp.Databases { + for _, database := range resp.Databases { if database.Id != nil && *database.Id == databaseId { return &database, nil } diff --git a/stackit/internal/services/postgresflex/database/resource_test.go b/stackit/internal/services/postgresflex/database/resource_test.go index d43e7e2fe..ff5f5d92c 100644 --- a/stackit/internal/services/postgresflex/database/resource_test.go +++ b/stackit/internal/services/postgresflex/database/resource_test.go @@ -5,7 +5,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" ) func TestMapFields(t *testing.T) { @@ -39,7 +39,7 @@ func TestMapFields(t *testing.T) { &postgresflex.InstanceDatabase{ Id: new("uid"), Name: new("dbname"), - Options: &map[string]any{ + Options: map[string]any{ "owner": "username", }, }, @@ -60,7 +60,7 @@ func TestMapFields(t *testing.T) { &postgresflex.InstanceDatabase{ Id: new("uid"), Name: new(""), - Options: &map[string]any{ + Options: map[string]any{ "owner": "", }, }, @@ -95,7 +95,7 @@ func TestMapFields(t *testing.T) { &postgresflex.InstanceDatabase{ Id: new(""), Name: new("dbname"), - Options: &map[string]any{ + Options: map[string]any{ "owner": "username", }, }, diff --git a/stackit/internal/services/postgresflex/instance/datasource.go b/stackit/internal/services/postgresflex/instance/datasource.go index 15ef99923..c10d38553 100644 --- a/stackit/internal/services/postgresflex/instance/datasource.go +++ b/stackit/internal/services/postgresflex/instance/datasource.go @@ -19,8 +19,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/wait" ) // Ensure the implementation satisfies the expected interfaces. @@ -124,7 +124,7 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques }, }, }, - "replicas": schema.Int64Attribute{ + "replicas": schema.Int32Attribute{ Computed: true, }, "storage": schema.SingleNestedAttribute{ @@ -167,7 +167,7 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "instance_id", instanceId) ctx = tflog.SetField(ctx, "region", region) - instanceResp, err := r.client.GetInstance(ctx, projectId, region, instanceId).Execute() + instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, region, instanceId).Execute() if err != nil { utils.LogError( ctx, diff --git a/stackit/internal/services/postgresflex/instance/resource.go b/stackit/internal/services/postgresflex/instance/resource.go index 347fbb412..be0306305 100644 --- a/stackit/internal/services/postgresflex/instance/resource.go +++ b/stackit/internal/services/postgresflex/instance/resource.go @@ -29,8 +29,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/wait" ) // Ensure the implementation satisfies the expected interfaces. @@ -49,7 +49,7 @@ type Model struct { ACL types.List `tfsdk:"acl"` BackupSchedule types.String `tfsdk:"backup_schedule"` Flavor types.Object `tfsdk:"flavor"` - Replicas types.Int64 `tfsdk:"replicas"` + Replicas types.Int32 `tfsdk:"replicas"` Storage types.Object `tfsdk:"storage"` Version types.String `tfsdk:"version"` Region types.String `tfsdk:"region"` @@ -238,7 +238,7 @@ func (r *instanceResource) Schema(_ context.Context, req resource.SchemaRequest, }, }, }, - "replicas": schema.Int64Attribute{ + "replicas": schema.Int32Attribute{ Description: descriptions["replicas"], Required: true, }, @@ -304,7 +304,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques if resp.Diagnostics.HasError() { return } - err := loadFlavorId(ctx, r.client, &model, flavor) + err := loadFlavorId(ctx, r.client.DefaultAPI, &model, flavor) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Loading flavor ID: %v", err)) return @@ -326,7 +326,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques return } // Create new instance - createResp, err := r.client.CreateInstance(ctx, projectId, region).CreateInstancePayload(*payload).Execute() + createResp, err := r.client.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Calling API: %v", err)) return @@ -349,7 +349,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques return } - waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).WaitWithContext(ctx) + waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -405,7 +405,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r } } - instanceResp, err := r.client.GetInstance(ctx, projectId, region, instanceId).Execute() + instanceResp, err := r.client.DefaultAPI.GetInstance(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 { @@ -472,7 +472,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques if resp.Diagnostics.HasError() { return } - err := loadFlavorId(ctx, r.client, &model, flavor) + err := loadFlavorId(ctx, r.client.DefaultAPI, &model, flavor) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Loading flavor ID: %v", err)) return @@ -494,7 +494,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques return } // Update existing instance - _, err = r.client.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(*payload).Execute() + _, err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", err.Error()) return @@ -502,7 +502,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques ctx = core.LogResponse(ctx) - waitResp, err := wait.PartialUpdateInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).WaitWithContext(ctx) + waitResp, err := wait.PartialUpdateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance update waiting: %v", err)) return @@ -542,7 +542,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques ctx = tflog.SetField(ctx, "region", region) // Delete existing instance - err := r.client.DeleteInstance(ctx, projectId, region, instanceId).Execute() + err := r.client.DefaultAPI.DeleteInstance(ctx, projectId, region, instanceId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err)) return @@ -550,7 +550,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques ctx = core.LogResponse(ctx) - _, err = wait.DeleteInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).SetTimeout(45 * time.Minute).WaitWithContext(ctx) + _, err = wait.DeleteInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId).SetTimeout(45 * time.Minute).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Instance deletion waiting: %v", err)) return @@ -605,7 +605,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model * if instance.Acl == nil || instance.Acl.Items == nil { aclList = types.ListNull(types.StringType) } else { - respACL := *instance.Acl.Items + respACL := instance.Acl.Items modelACL, err := utils.ListValuetoStringSlice(model.ACL) if err != nil { return err @@ -670,7 +670,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model * model.Name = types.StringPointerValue(instance.Name) model.ACL = aclList model.Flavor = flavorObject - model.Replicas = types.Int64PointerValue(instance.Replicas) + model.Replicas = types.Int32PointerValue(instance.Replicas) model.Storage = storageObject model.Version = types.StringPointerValue(instance.Version) model.Region = types.StringValue(region) @@ -692,18 +692,18 @@ func toCreatePayload(model *Model, acl []string, flavor *flavorModel, storage *s } return &postgresflex.CreateInstancePayload{ - Acl: &postgresflex.ACL{ - Items: &acl, + Acl: postgresflex.ACL{ + Items: acl, }, - BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule), - FlavorId: conversion.StringValueToPointer(flavor.Id), - Name: conversion.StringValueToPointer(model.Name), - Replicas: conversion.Int64ValueToPointer(model.Replicas), - Storage: &postgresflex.Storage{ + BackupSchedule: model.BackupSchedule.ValueString(), + FlavorId: flavor.Id.ValueString(), + Name: model.Name.ValueString(), + Replicas: model.Replicas.ValueInt32(), + Storage: postgresflex.Storage{ Class: conversion.StringValueToPointer(storage.Class), Size: conversion.Int64ValueToPointer(storage.Size), }, - Version: conversion.StringValueToPointer(model.Version), + Version: model.Version.ValueString(), }, nil } @@ -723,18 +723,19 @@ func toUpdatePayload(model *Model, acl []string, flavor *flavorModel, storage *s return &postgresflex.PartialUpdateInstancePayload{ Acl: &postgresflex.ACL{ - Items: &acl, + Items: acl, }, BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule), FlavorId: conversion.StringValueToPointer(flavor.Id), Name: conversion.StringValueToPointer(model.Name), - Replicas: conversion.Int64ValueToPointer(model.Replicas), + Replicas: conversion.Int32ValueToPointer(model.Replicas), Version: conversion.StringValueToPointer(model.Version), }, nil } type postgresFlexClient interface { - ListFlavorsExecute(ctx context.Context, projectId string, region string) (*postgresflex.ListFlavorsResponse, error) + ListFlavors(ctx context.Context, projectId, region string) postgresflex.ApiListFlavorsRequest + ListFlavorsExecute(r postgresflex.ApiListFlavorsRequest) (*postgresflex.ListFlavorsResponse, error) } func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model, flavor *flavorModel) error { @@ -755,7 +756,8 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model, projectId := model.ProjectId.ValueString() region := model.Region.ValueString() - res, err := client.ListFlavorsExecute(ctx, projectId, region) + req := client.ListFlavors(ctx, projectId, region) + res, err := client.ListFlavorsExecute(req) if err != nil { return fmt.Errorf("listing postgresflex flavors: %w", err) } @@ -764,7 +766,7 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model, if res.Flavors == nil { return fmt.Errorf("finding flavors for project %s", projectId) } - for _, f := range *res.Flavors { + for _, f := range res.Flavors { if f.Id == nil || f.Cpu == nil || f.Memory == nil { continue } diff --git a/stackit/internal/services/postgresflex/instance/resource_test.go b/stackit/internal/services/postgresflex/instance/resource_test.go index 75b0d195e..329295b3f 100644 --- a/stackit/internal/services/postgresflex/instance/resource_test.go +++ b/stackit/internal/services/postgresflex/instance/resource_test.go @@ -8,15 +8,20 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" ) type postgresFlexClientMocked struct { returnError bool getFlavorsResp *postgresflex.ListFlavorsResponse + listFlavorsReq postgresflex.ApiListFlavorsRequest } -func (c *postgresFlexClientMocked) ListFlavorsExecute(_ context.Context, _, _ string) (*postgresflex.ListFlavorsResponse, error) { +func (c *postgresFlexClientMocked) ListFlavors(_ context.Context, _, _ string) postgresflex.ApiListFlavorsRequest { + return c.listFlavorsReq +} + +func (c *postgresFlexClientMocked) ListFlavorsExecute(_ postgresflex.ApiListFlavorsRequest) (*postgresflex.ListFlavorsResponse, error) { if c.returnError { return nil, fmt.Errorf("get flavors failed") } @@ -41,7 +46,7 @@ func TestMapFields(t *testing.T) { "cpu": types.Int64Null(), "ram": types.Int64Null(), }), - Replicas: types.Int64Null(), + Replicas: types.Int32Null(), Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{ "class": types.StringNull(), "size": types.Int64Null(), @@ -91,7 +96,7 @@ func TestMapFields(t *testing.T) { &postgresflex.InstanceResponse{ Item: &postgresflex.Instance{ Acl: &postgresflex.ACL{ - Items: &[]string{ + Items: []string{ "ip1", "ip2", "", @@ -106,7 +111,7 @@ func TestMapFields(t *testing.T) { }, Id: new("iid"), Name: new("name"), - Replicas: new(int64(56)), + Replicas: new(int32(56)), Status: new("status"), Storage: &postgresflex.Storage{ Class: new("class"), @@ -135,7 +140,7 @@ func TestMapFields(t *testing.T) { "cpu": types.Int64Value(12), "ram": types.Int64Value(34), }), - Replicas: types.Int64Value(56), + Replicas: types.Int32Value(56), Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{ "class": types.StringValue("class"), "size": types.Int64Value(78), @@ -154,7 +159,7 @@ func TestMapFields(t *testing.T) { &postgresflex.InstanceResponse{ Item: &postgresflex.Instance{ Acl: &postgresflex.ACL{ - Items: &[]string{ + Items: []string{ "ip1", "ip2", "", @@ -164,7 +169,7 @@ func TestMapFields(t *testing.T) { Flavor: nil, Id: new("iid"), Name: new("name"), - Replicas: new(int64(56)), + Replicas: new(int32(56)), Status: new("status"), Storage: nil, Version: new("version"), @@ -196,7 +201,7 @@ func TestMapFields(t *testing.T) { "cpu": types.Int64Value(12), "ram": types.Int64Value(34), }), - Replicas: types.Int64Value(56), + Replicas: types.Int32Value(56), Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{ "class": types.StringValue("class"), "size": types.Int64Value(78), @@ -220,7 +225,7 @@ func TestMapFields(t *testing.T) { &postgresflex.InstanceResponse{ Item: &postgresflex.Instance{ Acl: &postgresflex.ACL{ - Items: &[]string{ + Items: []string{ "", "ip1", "ip2", @@ -230,7 +235,7 @@ func TestMapFields(t *testing.T) { Flavor: nil, Id: new("iid"), Name: new("name"), - Replicas: new(int64(56)), + Replicas: new(int32(56)), Status: new("status"), Storage: nil, Version: new("version"), @@ -262,7 +267,7 @@ func TestMapFields(t *testing.T) { "cpu": types.Int64Value(12), "ram": types.Int64Value(34), }), - Replicas: types.Int64Value(56), + Replicas: types.Int32Value(56), Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{ "class": types.StringValue("class"), "size": types.Int64Value(78), @@ -371,10 +376,10 @@ func TestToCreatePayload(t *testing.T) { &flavorModel{}, &storageModel{}, &postgresflex.CreateInstancePayload{ - Acl: &postgresflex.ACL{ - Items: &[]string{}, + Acl: postgresflex.ACL{ + Items: []string{}, }, - Storage: &postgresflex.Storage{}, + Storage: postgresflex.Storage{}, }, true, }, @@ -383,7 +388,7 @@ func TestToCreatePayload(t *testing.T) { &Model{ BackupSchedule: types.StringValue("schedule"), Name: types.StringValue("name"), - Replicas: types.Int64Value(12), + Replicas: types.Int32Value(12), Version: types.StringValue("version"), }, []string{ @@ -398,21 +403,21 @@ func TestToCreatePayload(t *testing.T) { Size: types.Int64Value(34), }, &postgresflex.CreateInstancePayload{ - Acl: &postgresflex.ACL{ - Items: &[]string{ + Acl: postgresflex.ACL{ + Items: []string{ "ip_1", "ip_2", }, }, - BackupSchedule: new("schedule"), - FlavorId: new("flavor_id"), - Name: new("name"), - Replicas: new(int64(12)), - Storage: &postgresflex.Storage{ + BackupSchedule: "schedule", + FlavorId: "flavor_id", + Name: "name", + Replicas: int32(12), + Storage: postgresflex.Storage{ Class: new("class"), Size: new(int64(34)), }, - Version: new("version"), + Version: "version", }, true, }, @@ -421,7 +426,7 @@ func TestToCreatePayload(t *testing.T) { &Model{ BackupSchedule: types.StringNull(), Name: types.StringNull(), - Replicas: types.Int64Value(2123456789), + Replicas: types.Int32Value(2123456789), Version: types.StringNull(), }, []string{ @@ -435,20 +440,20 @@ func TestToCreatePayload(t *testing.T) { Size: types.Int64Null(), }, &postgresflex.CreateInstancePayload{ - Acl: &postgresflex.ACL{ - Items: &[]string{ + Acl: postgresflex.ACL{ + Items: []string{ "", }, }, - BackupSchedule: nil, - FlavorId: nil, - Name: nil, - Replicas: new(int64(2123456789)), - Storage: &postgresflex.Storage{ + BackupSchedule: "", + FlavorId: "", + Name: "", + Replicas: int32(2123456789), + Storage: postgresflex.Storage{ Class: nil, Size: nil, }, - Version: nil, + Version: "", }, true, }, @@ -526,7 +531,7 @@ func TestToUpdatePayload(t *testing.T) { &storageModel{}, &postgresflex.PartialUpdateInstancePayload{ Acl: &postgresflex.ACL{ - Items: &[]string{}, + Items: []string{}, }, }, true, @@ -536,7 +541,7 @@ func TestToUpdatePayload(t *testing.T) { &Model{ BackupSchedule: types.StringValue("schedule"), Name: types.StringValue("name"), - Replicas: types.Int64Value(12), + Replicas: types.Int32Value(12), Version: types.StringValue("version"), }, []string{ @@ -552,7 +557,7 @@ func TestToUpdatePayload(t *testing.T) { }, &postgresflex.PartialUpdateInstancePayload{ Acl: &postgresflex.ACL{ - Items: &[]string{ + Items: []string{ "ip_1", "ip_2", }, @@ -560,7 +565,7 @@ func TestToUpdatePayload(t *testing.T) { BackupSchedule: new("schedule"), FlavorId: new("flavor_id"), Name: new("name"), - Replicas: new(int64(12)), + Replicas: new(int32(12)), Version: new("version"), }, true, @@ -570,7 +575,7 @@ func TestToUpdatePayload(t *testing.T) { &Model{ BackupSchedule: types.StringNull(), Name: types.StringNull(), - Replicas: types.Int64Value(2123456789), + Replicas: types.Int32Value(2123456789), Version: types.StringNull(), }, []string{ @@ -585,14 +590,14 @@ func TestToUpdatePayload(t *testing.T) { }, &postgresflex.PartialUpdateInstancePayload{ Acl: &postgresflex.ACL{ - Items: &[]string{ + Items: []string{ "", }, }, BackupSchedule: nil, FlavorId: nil, Name: nil, - Replicas: new(int64(2123456789)), + Replicas: new(int32(2123456789)), Version: nil, }, true, @@ -669,7 +674,7 @@ func TestLoadFlavorId(t *testing.T) { RAM: types.Int64Value(8), }, &postgresflex.ListFlavorsResponse{ - Flavors: &[]postgresflex.Flavor{ + Flavors: []postgresflex.Flavor{ { Id: new("fid-1"), Cpu: new(int64(2)), @@ -694,7 +699,7 @@ func TestLoadFlavorId(t *testing.T) { RAM: types.Int64Value(8), }, &postgresflex.ListFlavorsResponse{ - Flavors: &[]postgresflex.Flavor{ + Flavors: []postgresflex.Flavor{ { Id: new("fid-1"), Cpu: new(int64(2)), @@ -725,7 +730,7 @@ func TestLoadFlavorId(t *testing.T) { RAM: types.Int64Value(8), }, &postgresflex.ListFlavorsResponse{ - Flavors: &[]postgresflex.Flavor{ + Flavors: []postgresflex.Flavor{ { Id: new("fid-1"), Cpu: new(int64(1)), diff --git a/stackit/internal/services/postgresflex/postgresflex_acc_test.go b/stackit/internal/services/postgresflex/postgresflex_acc_test.go index c1d1d60a3..43a854d3d 100644 --- a/stackit/internal/services/postgresflex/postgresflex_acc_test.go +++ b/stackit/internal/services/postgresflex/postgresflex_acc_test.go @@ -11,8 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" @@ -348,22 +348,22 @@ func testAccCheckPostgresFlexDestroy(s *terraform.State) error { instancesToDestroy = append(instancesToDestroy, instanceId) } - instancesResp, err := client.ListInstances(ctx, testutil.ProjectId, testutil.Region).Execute() + instancesResp, err := client.DefaultAPI.ListInstances(ctx, testutil.ProjectId, testutil.Region).Execute() if err != nil { return fmt.Errorf("getting instancesResp: %w", err) } - items := *instancesResp.Items + items := instancesResp.Items for i := range items { if items[i].Id == nil { continue } if sdkUtils.Contains(instancesToDestroy, *items[i].Id) { - err := client.ForceDeleteInstanceExecute(ctx, testutil.ProjectId, testutil.Region, *items[i].Id) + err := client.DefaultAPI.ForceDeleteInstance(ctx, testutil.ProjectId, testutil.Region, *items[i].Id).Execute() if err != nil { return fmt.Errorf("deleting instance %s during CheckDestroy: %w", *items[i].Id, err) } - _, err = wait.DeleteInstanceWaitHandler(ctx, client, testutil.ProjectId, testutil.Region, *items[i].Id).WaitWithContext(ctx) + _, err = wait.DeleteInstanceWaitHandler(ctx, client.DefaultAPI, testutil.ProjectId, testutil.Region, *items[i].Id).WaitWithContext(ctx) if err != nil { return fmt.Errorf("deleting instance %s during CheckDestroy: waiting for deletion %w", *items[i].Id, err) } diff --git a/stackit/internal/services/postgresflex/user/datasource.go b/stackit/internal/services/postgresflex/user/datasource.go index 5934b2fc6..404590ae9 100644 --- a/stackit/internal/services/postgresflex/user/datasource.go +++ b/stackit/internal/services/postgresflex/user/datasource.go @@ -19,7 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -154,7 +154,7 @@ func (r *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r ctx = tflog.SetField(ctx, "user_id", userId) ctx = tflog.SetField(ctx, "region", region) - recordSetResp, err := r.client.GetUser(ctx, projectId, region, instanceId, userId).Execute() + recordSetResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, region, instanceId, userId).Execute() if err != nil { utils.LogError( ctx, @@ -215,7 +215,7 @@ func mapDataSourceFields(userResp *postgresflex.GetUserResponse, model *DataSour model.Roles = types.SetNull(types.StringType) } else { roles := []attr.Value{} - for _, role := range *user.Roles { + for _, role := range user.Roles { roles = append(roles, types.StringValue(role)) } rolesSet, diags := types.SetValue(types.StringType, roles) diff --git a/stackit/internal/services/postgresflex/user/datasource_test.go b/stackit/internal/services/postgresflex/user/datasource_test.go index 5132665ee..80807a3d1 100644 --- a/stackit/internal/services/postgresflex/user/datasource_test.go +++ b/stackit/internal/services/postgresflex/user/datasource_test.go @@ -6,7 +6,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" ) func TestMapDataSourceFields(t *testing.T) { @@ -41,7 +41,7 @@ func TestMapDataSourceFields(t *testing.T) { "simple_values", &postgresflex.GetUserResponse{ Item: &postgresflex.UserResponse{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", "", @@ -74,7 +74,7 @@ func TestMapDataSourceFields(t *testing.T) { &postgresflex.GetUserResponse{ Item: &postgresflex.UserResponse{ Id: new("uid"), - Roles: &[]string{}, + Roles: []string{}, Username: nil, Host: nil, Port: new(int64(2123456789)), diff --git a/stackit/internal/services/postgresflex/user/resource.go b/stackit/internal/services/postgresflex/user/resource.go index 61d3bad73..4a491a0e9 100644 --- a/stackit/internal/services/postgresflex/user/resource.go +++ b/stackit/internal/services/postgresflex/user/resource.go @@ -24,8 +24,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/wait" ) // Ensure the implementation satisfies the expected interfaces. @@ -240,7 +240,7 @@ func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, r return } // Create new user - userResp, err := r.client.CreateUser(ctx, projectId, region, instanceId).CreateUserPayload(*payload).Execute() + userResp, err := r.client.DefaultAPI.CreateUser(ctx, projectId, region, instanceId).CreateUserPayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err)) return @@ -290,7 +290,7 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp ctx = tflog.SetField(ctx, "user_id", userId) ctx = tflog.SetField(ctx, "region", region) - recordSetResp, err := r.client.GetUser(ctx, projectId, region, instanceId, userId).Execute() + recordSetResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, region, instanceId, userId).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 { @@ -365,7 +365,7 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r } // Update existing instance - err = r.client.UpdateUser(ctx, projectId, region, instanceId, userId).UpdateUserPayload(*payload).Execute() + err = r.client.DefaultAPI.UpdateUser(ctx, projectId, region, instanceId, userId).UpdateUserPayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", err.Error()) return @@ -373,7 +373,7 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r ctx = core.LogResponse(ctx) - userResp, err := r.client.GetUser(ctx, projectId, region, instanceId, userId).Execute() + userResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, region, instanceId, userId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Calling API: %v", err)) return @@ -417,14 +417,14 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r ctx = tflog.SetField(ctx, "region", region) // Delete existing record set - err := r.client.DeleteUser(ctx, projectId, region, instanceId, userId).Execute() + err := r.client.DefaultAPI.DeleteUser(ctx, projectId, region, instanceId, userId).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err)) } ctx = core.LogResponse(ctx) - _, err = wait.DeleteUserWaitHandler(ctx, r.client, projectId, region, instanceId, userId).WaitWithContext(ctx) + _, err = wait.DeleteUserWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId, userId).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Instance deletion waiting: %v", err)) return @@ -483,7 +483,7 @@ func mapFieldsCreate(userResp *postgresflex.CreateUserResponse, model *Model, re model.Roles = types.SetNull(types.StringType) } else { roles := []attr.Value{} - for _, role := range *user.Roles { + for _, role := range user.Roles { roles = append(roles, types.StringValue(role)) } rolesSet, diags := types.SetValue(types.StringType, roles) @@ -526,7 +526,7 @@ func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region stri model.Roles = types.SetNull(types.StringType) } else { roles := []attr.Value{} - for _, role := range *user.Roles { + for _, role := range user.Roles { roles = append(roles, types.StringValue(role)) } rolesSet, diags := types.SetValue(types.StringType, roles) @@ -550,7 +550,7 @@ func toCreatePayload(model *Model, roles []string) (*postgresflex.CreateUserPayl } return &postgresflex.CreateUserPayload{ - Roles: &roles, + Roles: roles, Username: conversion.StringValueToPointer(model.Username), }, nil } @@ -564,6 +564,6 @@ func toUpdatePayload(model *Model, roles []string) (*postgresflex.UpdateUserPayl } return &postgresflex.UpdateUserPayload{ - Roles: &roles, + Roles: roles, }, nil } diff --git a/stackit/internal/services/postgresflex/user/resource_test.go b/stackit/internal/services/postgresflex/user/resource_test.go index e3f38a05a..06b04340a 100644 --- a/stackit/internal/services/postgresflex/user/resource_test.go +++ b/stackit/internal/services/postgresflex/user/resource_test.go @@ -6,7 +6,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" ) func TestMapFieldsCreate(t *testing.T) { @@ -47,7 +47,7 @@ func TestMapFieldsCreate(t *testing.T) { &postgresflex.CreateUserResponse{ Item: &postgresflex.User{ Id: new("uid"), - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", "", @@ -84,7 +84,7 @@ func TestMapFieldsCreate(t *testing.T) { &postgresflex.CreateUserResponse{ Item: &postgresflex.User{ Id: new("uid"), - Roles: &[]string{}, + Roles: []string{}, Username: nil, Password: new(""), Host: nil, @@ -198,7 +198,7 @@ func TestMapFields(t *testing.T) { "simple_values", &postgresflex.GetUserResponse{ Item: &postgresflex.UserResponse{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", "", @@ -231,7 +231,7 @@ func TestMapFields(t *testing.T) { &postgresflex.GetUserResponse{ Item: &postgresflex.UserResponse{ Id: new("uid"), - Roles: &[]string{}, + Roles: []string{}, Username: nil, Host: nil, Port: new(int64(2123456789)), @@ -312,7 +312,7 @@ func TestToCreatePayload(t *testing.T) { &Model{}, []string{}, &postgresflex.CreateUserPayload{ - Roles: &[]string{}, + Roles: []string{}, Username: nil, }, true, @@ -327,7 +327,7 @@ func TestToCreatePayload(t *testing.T) { "role_2", }, &postgresflex.CreateUserPayload{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", }, @@ -344,7 +344,7 @@ func TestToCreatePayload(t *testing.T) { "", }, &postgresflex.CreateUserPayload{ - Roles: &[]string{ + Roles: []string{ "", }, Username: nil, @@ -398,7 +398,7 @@ func TestToUpdatePayload(t *testing.T) { &Model{}, []string{}, &postgresflex.UpdateUserPayload{ - Roles: &[]string{}, + Roles: []string{}, }, true, }, @@ -412,7 +412,7 @@ func TestToUpdatePayload(t *testing.T) { "role_2", }, &postgresflex.UpdateUserPayload{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", }, @@ -428,7 +428,7 @@ func TestToUpdatePayload(t *testing.T) { "", }, &postgresflex.UpdateUserPayload{ - Roles: &[]string{ + Roles: []string{ "", }, }, diff --git a/stackit/internal/services/postgresflex/utils/util.go b/stackit/internal/services/postgresflex/utils/util.go index 52dee4c4f..71a236a87 100644 --- a/stackit/internal/services/postgresflex/utils/util.go +++ b/stackit/internal/services/postgresflex/utils/util.go @@ -6,7 +6,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" @@ -19,9 +20,8 @@ func ConfigureClient(ctx context.Context, providerData *core.ProviderData, diags } if providerData.PostgresFlexCustomEndpoint != "" { apiClientConfigOptions = append(apiClientConfigOptions, config.WithEndpoint(providerData.PostgresFlexCustomEndpoint)) - } else { - apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(providerData.GetRegion())) } + apiClient, err := postgresflex.NewAPIClient(apiClientConfigOptions...) if err != nil { core.LogAndAddError(ctx, diags, "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration", err)) diff --git a/stackit/internal/services/postgresflex/utils/util_test.go b/stackit/internal/services/postgresflex/utils/util_test.go index c42ab9cbe..b1e1ac1dc 100644 --- a/stackit/internal/services/postgresflex/utils/util_test.go +++ b/stackit/internal/services/postgresflex/utils/util_test.go @@ -9,7 +9,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients" "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" + + postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" @@ -46,7 +47,6 @@ func TestConfigureClient(t *testing.T) { }, expected: func() *postgresflex.APIClient { apiClient, err := postgresflex.NewAPIClient( - config.WithRegion("eu01"), utils.UserAgentConfigOption(testVersion), ) if err != nil {