From 5bbde56211953f04872544de0dcfc5ceccffcdd8 Mon Sep 17 00:00:00 2001 From: GokceGK Date: Tue, 7 Apr 2026 10:54:38 +0200 Subject: [PATCH 1/2] chore(mongodbflex): switch to new SDK structure --- go.mod | 2 +- go.sum | 2 + .../mongodbflex/instance/datasource.go | 20 +- .../services/mongodbflex/instance/resource.go | 210 ++++----- .../mongodbflex/instance/resource_test.go | 404 +++++++++--------- .../mongodbflex/mongodbflex_acc_test.go | 12 +- .../services/mongodbflex/mongodbflex_test.go | 17 +- .../services/mongodbflex/user/datasource.go | 6 +- .../mongodbflex/user/datasource_test.go | 19 +- .../services/mongodbflex/user/resource.go | 24 +- .../mongodbflex/user/resource_test.go | 75 ++-- .../services/mongodbflex/utils/util.go | 2 +- .../services/mongodbflex/utils/util_test.go | 2 +- 13 files changed, 404 insertions(+), 391 deletions(-) diff --git a/go.mod b/go.mod index dcd1bc28a..c7ec15ab5 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/logs v0.7.1 github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.27.1 github.com/stackitcloud/stackit-sdk-go/services/modelserving v0.8.1 - github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.7.1 + github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.7.2 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 diff --git a/go.sum b/go.sum index 33b90f01a..3aa5fca8c 100644 --- a/go.sum +++ b/go.sum @@ -185,6 +185,8 @@ github.com/stackitcloud/stackit-sdk-go/services/modelserving v0.8.1 h1:qBPfWK6Xp github.com/stackitcloud/stackit-sdk-go/services/modelserving v0.8.1/go.mod h1:b8L6f68HZce01y+eZ1o7KTRAkgpWhggpvakAEwnxnCs= github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.7.1 h1:8HFqfUI35Uk5QHUr3+VO21KXstzUl5zDKFrMuVOx+BI= github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.7.1/go.mod h1:an5vc+0PL6OBMqFl75uuQpVGyzWHBpoxc9a5p41fFA8= +github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.7.2 h1:ymhDgp6+RXBvmi9nugaVCi3MN0q2pC62SD+Nh5nTB84= +github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v1.7.2/go.mod h1:gm7KzHv788MZ2BPimrlRk3ueV8EBN4JACg/MtotGC70= github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0 h1:UxnbsKm6PQV8Gudw/EhySaEh9q1xSaTG8mzJz1EvhnE= github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0/go.mod h1:RFL4h6JZvpsyFYbdJ3+eINEkletzJQTfrPdd+yPT/fU= github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0 h1:LGwCvvST0fwUgZ6bOxYIfu45qqTgv421ZS07UhKjZL8= diff --git a/stackit/internal/services/mongodbflex/instance/datasource.go b/stackit/internal/services/mongodbflex/instance/datasource.go index 84d7563cb..eebb20a6a 100644 --- a/stackit/internal/services/mongodbflex/instance/datasource.go +++ b/stackit/internal/services/mongodbflex/instance/datasource.go @@ -18,7 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -123,15 +123,15 @@ func (d *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques "description": schema.StringAttribute{ Computed: true, }, - "cpu": schema.Int64Attribute{ + "cpu": schema.Int32Attribute{ Computed: true, }, - "ram": schema.Int64Attribute{ + "ram": schema.Int32Attribute{ Computed: true, }, }, }, - "replicas": schema.Int64Attribute{ + "replicas": schema.Int32Attribute{ Computed: true, }, "storage": schema.SingleNestedAttribute{ @@ -156,23 +156,23 @@ func (d *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: descriptions["type"], Computed: true, }, - "snapshot_retention_days": schema.Int64Attribute{ + "snapshot_retention_days": schema.Int32Attribute{ Description: descriptions["snapshot_retention_days"], Computed: true, }, - "daily_snapshot_retention_days": schema.Int64Attribute{ + "daily_snapshot_retention_days": schema.Int32Attribute{ Description: descriptions["daily_snapshot_retention_days"], Computed: true, }, - "weekly_snapshot_retention_weeks": schema.Int64Attribute{ + "weekly_snapshot_retention_weeks": schema.Int32Attribute{ Description: descriptions["weekly_snapshot_retention_weeks"], Computed: true, }, - "monthly_snapshot_retention_months": schema.Int64Attribute{ + "monthly_snapshot_retention_months": schema.Int32Attribute{ Description: descriptions["monthly_snapshot_retention_months"], Computed: true, }, - "point_in_time_window_hours": schema.Int64Attribute{ + "point_in_time_window_hours": schema.Int32Attribute{ Description: descriptions["point_in_time_window_hours"], Computed: true, }, @@ -205,7 +205,7 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques ctx = tflog.SetField(ctx, "project_id", projectId) ctx = tflog.SetField(ctx, "region", region) ctx = tflog.SetField(ctx, "instance_id", instanceId) - instanceResp, err := d.client.GetInstance(ctx, projectId, instanceId, region).Execute() + instanceResp, err := d.client.DefaultAPI.GetInstance(ctx, projectId, instanceId, region).Execute() if err != nil { utils.LogError( ctx, diff --git a/stackit/internal/services/mongodbflex/instance/resource.go b/stackit/internal/services/mongodbflex/instance/resource.go index 03e3b4d0a..7b75fc3b9 100644 --- a/stackit/internal/services/mongodbflex/instance/resource.go +++ b/stackit/internal/services/mongodbflex/instance/resource.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier" mongodbflexUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mongodbflex/utils" stringplanmodifierCustom "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils/planmodifiers/stringplanmodifier" @@ -25,13 +26,12 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "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/mongodbflex" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/wait" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api/wait" ) // Ensure the implementation satisfies the expected interfaces. @@ -50,7 +50,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"` Options types.Object `tfsdk:"options"` @@ -61,16 +61,16 @@ type Model struct { type flavorModel struct { Id types.String `tfsdk:"id"` Description types.String `tfsdk:"description"` - CPU types.Int64 `tfsdk:"cpu"` - RAM types.Int64 `tfsdk:"ram"` + CPU types.Int32 `tfsdk:"cpu"` + RAM types.Int32 `tfsdk:"ram"` } // Types corresponding to flavorModel var flavorTypes = map[string]attr.Type{ "id": basetypes.StringType{}, "description": basetypes.StringType{}, - "cpu": basetypes.Int64Type{}, - "ram": basetypes.Int64Type{}, + "cpu": basetypes.Int32Type{}, + "ram": basetypes.Int32Type{}, } // Struct corresponding to Model.Storage @@ -88,21 +88,21 @@ var storageTypes = map[string]attr.Type{ // Struct corresponding to Model.Options type optionsModel struct { Type types.String `tfsdk:"type"` - SnapshotRetentionDays types.Int64 `tfsdk:"snapshot_retention_days"` - PointInTimeWindowHours types.Int64 `tfsdk:"point_in_time_window_hours"` - DailySnapshotRetentionDays types.Int64 `tfsdk:"daily_snapshot_retention_days"` - WeeklySnapshotRetentionWeeks types.Int64 `tfsdk:"weekly_snapshot_retention_weeks"` - MonthlySnapshotRetentionMonths types.Int64 `tfsdk:"monthly_snapshot_retention_months"` + SnapshotRetentionDays types.Int32 `tfsdk:"snapshot_retention_days"` + PointInTimeWindowHours types.Int32 `tfsdk:"point_in_time_window_hours"` + DailySnapshotRetentionDays types.Int32 `tfsdk:"daily_snapshot_retention_days"` + WeeklySnapshotRetentionWeeks types.Int32 `tfsdk:"weekly_snapshot_retention_weeks"` + MonthlySnapshotRetentionMonths types.Int32 `tfsdk:"monthly_snapshot_retention_months"` } // Types corresponding to optionsModel var optionsTypes = map[string]attr.Type{ "type": basetypes.StringType{}, - "snapshot_retention_days": basetypes.Int64Type{}, - "point_in_time_window_hours": basetypes.Int64Type{}, - "daily_snapshot_retention_days": basetypes.Int64Type{}, - "weekly_snapshot_retention_weeks": basetypes.Int64Type{}, - "monthly_snapshot_retention_months": basetypes.Int64Type{}, + "snapshot_retention_days": basetypes.Int32Type{}, + "point_in_time_window_hours": basetypes.Int32Type{}, + "daily_snapshot_retention_days": basetypes.Int32Type{}, + "weekly_snapshot_retention_weeks": basetypes.Int32Type{}, + "monthly_snapshot_retention_months": basetypes.Int32Type{}, } // NewInstanceResource is a helper function to simplify the provider implementation. @@ -254,18 +254,18 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r "description": schema.StringAttribute{ Computed: true, }, - "cpu": schema.Int64Attribute{ + "cpu": schema.Int32Attribute{ Required: true, }, - "ram": schema.Int64Attribute{ + "ram": schema.Int32Attribute{ Required: true, }, }, }, - "replicas": schema.Int64Attribute{ + "replicas": schema.Int32Attribute{ Required: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.RequiresReplace(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.RequiresReplace(), }, }, "storage": schema.SingleNestedAttribute{ @@ -295,43 +295,43 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r stringplanmodifier.RequiresReplace(), }, }, - "snapshot_retention_days": schema.Int64Attribute{ + "snapshot_retention_days": schema.Int32Attribute{ Description: descriptions["snapshot_retention_days"], Optional: true, Computed: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.UseStateForUnknown(), }, }, - "daily_snapshot_retention_days": schema.Int64Attribute{ + "daily_snapshot_retention_days": schema.Int32Attribute{ Description: descriptions["daily_snapshot_retention_days"], Optional: true, Computed: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.UseStateForUnknown(), }, }, - "weekly_snapshot_retention_weeks": schema.Int64Attribute{ + "weekly_snapshot_retention_weeks": schema.Int32Attribute{ Description: descriptions["weekly_snapshot_retention_weeks"], Optional: true, Computed: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.UseStateForUnknown(), }, }, - "monthly_snapshot_retention_months": schema.Int64Attribute{ + "monthly_snapshot_retention_months": schema.Int32Attribute{ Description: descriptions["monthly_snapshot_retention_months"], Optional: true, Computed: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.UseStateForUnknown(), }, }, - "point_in_time_window_hours": schema.Int64Attribute{ + "point_in_time_window_hours": schema.Int32Attribute{ Description: descriptions["point_in_time_window_hours"], Required: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.UseStateForUnknown(), }, }, }, @@ -381,7 +381,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques if resp.Diagnostics.HasError() { return } - err := loadFlavorId(ctx, r.client, &model, flavor, region) + err := loadFlavorId(ctx, r.client.DefaultAPI, &model, flavor, region) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Loading flavor ID: %v", err)) return @@ -412,7 +412,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 @@ -437,7 +437,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques if resp.Diagnostics.HasError() { return } - waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, instanceId, region).WaitWithContext(ctx) + waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, region).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Instance creation waiting: %v", err)) return @@ -461,7 +461,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Creating API payload: %v", err)) return } - backupScheduleOptions, err := r.client.UpdateBackupSchedule(ctx, projectId, instanceId, region).UpdateBackupSchedulePayload(*backupScheduleOptionsPayload).Execute() + backupScheduleOptions, err := r.client.DefaultAPI.UpdateBackupSchedule(ctx, projectId, instanceId, region).UpdateBackupSchedulePayload(*backupScheduleOptionsPayload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Updating options: %v", err)) return @@ -526,7 +526,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r } } - instanceResp, err := r.client.GetInstance(ctx, projectId, instanceId, region).Execute() + instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, instanceId, region).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 { @@ -588,7 +588,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques if resp.Diagnostics.HasError() { return } - err := loadFlavorId(ctx, r.client, &model, flavor, region) + err := loadFlavorId(ctx, r.client.DefaultAPI, &model, flavor, region) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Loading flavor ID: %v", err)) return @@ -619,7 +619,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques return } // Update existing instance - _, err = r.client.PartialUpdateInstance(ctx, projectId, instanceId, region).PartialUpdateInstancePayload(*payload).Execute() + _, err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, instanceId, region).PartialUpdateInstancePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", err.Error()) return @@ -627,7 +627,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques ctx = core.LogResponse(ctx) - waitResp, err := wait.UpdateInstanceWaitHandler(ctx, r.client, projectId, instanceId, region).WaitWithContext(ctx) + waitResp, err := wait.UpdateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, region).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance update waiting: %v", err)) return @@ -645,7 +645,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Creating API payload: %v", err)) return } - backupScheduleOptions, err := r.client.UpdateBackupSchedule(ctx, projectId, instanceId, region).UpdateBackupSchedulePayload(*backupScheduleOptionsPayload).Execute() + backupScheduleOptions, err := r.client.DefaultAPI.UpdateBackupSchedule(ctx, projectId, instanceId, region).UpdateBackupSchedulePayload(*backupScheduleOptionsPayload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Updating options: %v", err)) return @@ -685,7 +685,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques ctx = tflog.SetField(ctx, "instance_id", instanceId) // Delete existing instance - err := r.client.DeleteInstance(ctx, projectId, instanceId, region).Execute() + err := r.client.DefaultAPI.DeleteInstance(ctx, projectId, instanceId, region).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err)) return @@ -693,7 +693,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques ctx = core.LogResponse(ctx) - _, err = wait.DeleteInstanceWaitHandler(ctx, r.client, projectId, instanceId, region).WaitWithContext(ctx) + _, err = wait.DeleteInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, region).WaitWithContext(ctx) if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Instance deletion waiting: %v", err)) return @@ -753,7 +753,7 @@ func mapFields(ctx context.Context, resp *mongodbflex.InstanceResponse, model *M 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 @@ -779,8 +779,8 @@ func mapFields(ctx context.Context, resp *mongodbflex.InstanceResponse, model *M flavorValues = map[string]attr.Value{ "id": types.StringValue(*instance.Flavor.Id), "description": types.StringValue(*instance.Flavor.Description), - "cpu": types.Int64PointerValue(instance.Flavor.Cpu), - "ram": types.Int64PointerValue(instance.Flavor.Memory), + "cpu": types.Int32PointerValue(instance.Flavor.Cpu), + "ram": types.Int32PointerValue(instance.Flavor.Memory), } } flavorObject, diags := types.ObjectValue(flavorTypes, flavorValues) @@ -809,46 +809,46 @@ func mapFields(ctx context.Context, resp *mongodbflex.InstanceResponse, model *M if instance.Options == nil { optionsValues = map[string]attr.Value{ "type": options.Type, - "snapshot_retention_days": types.Int64Null(), - "daily_snapshot_retention_days": types.Int64Null(), - "weekly_snapshot_retention_weeks": types.Int64Null(), - "monthly_snapshot_retention_months": types.Int64Null(), - "point_in_time_window_hours": types.Int64Null(), + "snapshot_retention_days": types.Int32Null(), + "daily_snapshot_retention_days": types.Int32Null(), + "weekly_snapshot_retention_weeks": types.Int32Null(), + "monthly_snapshot_retention_months": types.Int32Null(), + "point_in_time_window_hours": types.Int32Null(), } } else { snapshotRetentionDaysStr := (*instance.Options)["snapshotRetentionDays"] - snapshotRetentionDays, err := strconv.ParseInt(snapshotRetentionDaysStr, 10, 64) + snapshotRetentionDays, err := strconv.ParseInt(snapshotRetentionDaysStr, 10, 32) if err != nil { return fmt.Errorf("parse snapshot retention days: %w", err) } dailySnapshotRetentionDaysStr := (*instance.Options)["dailySnapshotRetentionDays"] - dailySnapshotRetentionDays, err := strconv.ParseInt(dailySnapshotRetentionDaysStr, 10, 64) + dailySnapshotRetentionDays, err := strconv.ParseInt(dailySnapshotRetentionDaysStr, 10, 32) if err != nil { return fmt.Errorf("parse daily snapshot retention days: %w", err) } weeklySnapshotRetentionWeeksStr := (*instance.Options)["weeklySnapshotRetentionWeeks"] - weeklySnapshotRetentionWeeks, err := strconv.ParseInt(weeklySnapshotRetentionWeeksStr, 10, 64) + weeklySnapshotRetentionWeeks, err := strconv.ParseInt(weeklySnapshotRetentionWeeksStr, 10, 32) if err != nil { return fmt.Errorf("parse weekly snapshot retention weeks: %w", err) } monthlySnapshotRetentionMonthsStr := (*instance.Options)["monthlySnapshotRetentionMonths"] - monthlySnapshotRetentionMonths, err := strconv.ParseInt(monthlySnapshotRetentionMonthsStr, 10, 64) + monthlySnapshotRetentionMonths, err := strconv.ParseInt(monthlySnapshotRetentionMonthsStr, 10, 32) if err != nil { return fmt.Errorf("parse monthly snapshot retention months: %w", err) } pointInTimeWindowHoursStr := (*instance.Options)["pointInTimeWindowHours"] - pointInTimeWindowHours, err := strconv.ParseInt(pointInTimeWindowHoursStr, 10, 64) + pointInTimeWindowHours, err := strconv.ParseInt(pointInTimeWindowHoursStr, 10, 32) if err != nil { return fmt.Errorf("parse point in time window hours: %w", err) } optionsValues = map[string]attr.Value{ "type": types.StringValue((*instance.Options)["type"]), - "snapshot_retention_days": types.Int64Value(snapshotRetentionDays), - "daily_snapshot_retention_days": types.Int64Value(dailySnapshotRetentionDays), - "weekly_snapshot_retention_weeks": types.Int64Value(weeklySnapshotRetentionWeeks), - "monthly_snapshot_retention_months": types.Int64Value(monthlySnapshotRetentionMonths), - "point_in_time_window_hours": types.Int64Value(pointInTimeWindowHours), + "snapshot_retention_days": types.Int32Value(int32(snapshotRetentionDays)), + "daily_snapshot_retention_days": types.Int32Value(int32(dailySnapshotRetentionDays)), + "weekly_snapshot_retention_weeks": types.Int32Value(int32(weeklySnapshotRetentionWeeks)), + "monthly_snapshot_retention_months": types.Int32Value(int32(monthlySnapshotRetentionMonths)), + "point_in_time_window_hours": types.Int32Value(int32(pointInTimeWindowHours)), } } optionsObject, diags := types.ObjectValue(optionsTypes, optionsValues) @@ -870,7 +870,7 @@ func mapFields(ctx context.Context, resp *mongodbflex.InstanceResponse, model *M 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.Options = optionsObject @@ -882,20 +882,20 @@ func mapOptions(model *Model, options *optionsModel, backupScheduleOptions *mong if backupScheduleOptions == nil { optionsValues = map[string]attr.Value{ "type": options.Type, - "snapshot_retention_days": types.Int64Null(), - "daily_snapshot_retention_days": types.Int64Null(), - "weekly_snapshot_retention_weeks": types.Int64Null(), - "monthly_snapshot_retention_months": types.Int64Null(), - "point_in_time_window_hours": types.Int64Null(), + "snapshot_retention_days": types.Int32Null(), + "daily_snapshot_retention_days": types.Int32Null(), + "weekly_snapshot_retention_weeks": types.Int32Null(), + "monthly_snapshot_retention_months": types.Int32Null(), + "point_in_time_window_hours": types.Int32Null(), } } else { optionsValues = map[string]attr.Value{ "type": options.Type, - "snapshot_retention_days": types.Int64Value(*backupScheduleOptions.SnapshotRetentionDays), - "daily_snapshot_retention_days": types.Int64Value(*backupScheduleOptions.DailySnapshotRetentionDays), - "weekly_snapshot_retention_weeks": types.Int64Value(*backupScheduleOptions.WeeklySnapshotRetentionWeeks), - "monthly_snapshot_retention_months": types.Int64Value(*backupScheduleOptions.MonthlySnapshotRetentionMonths), - "point_in_time_window_hours": types.Int64Value(*backupScheduleOptions.PointInTimeWindowHours), + "snapshot_retention_days": types.Int32Value(*backupScheduleOptions.SnapshotRetentionDays), + "daily_snapshot_retention_days": types.Int32Value(*backupScheduleOptions.DailySnapshotRetentionDays), + "weekly_snapshot_retention_weeks": types.Int32Value(*backupScheduleOptions.WeeklySnapshotRetentionWeeks), + "monthly_snapshot_retention_months": types.Int32Value(*backupScheduleOptions.MonthlySnapshotRetentionMonths), + "point_in_time_window_hours": types.Int32Value(*backupScheduleOptions.PointInTimeWindowHours), } } optionsTF, diags := types.ObjectValue(optionsTypes, optionsValues) @@ -929,19 +929,19 @@ func toCreatePayload(model *Model, acl []string, flavor *flavorModel, storage *s } return &mongodbflex.CreateInstancePayload{ - Acl: &mongodbflex.CreateInstancePayloadAcl{ - Items: &acl, + Acl: mongodbflex.ACL{ + Items: acl, }, - BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule), - FlavorId: conversion.StringValueToPointer(flavor.Id), - Name: conversion.StringValueToPointer(model.Name), - Replicas: conversion.Int64ValueToPointer(model.Replicas), - Storage: &mongodbflex.Storage{ + BackupSchedule: model.BackupSchedule.ValueString(), + FlavorId: flavor.Id.ValueString(), + Name: model.Name.ValueString(), + Replicas: model.Replicas.ValueInt32(), + Storage: mongodbflex.Storage{ Class: conversion.StringValueToPointer(storage.Class), Size: conversion.Int64ValueToPointer(storage.Size), }, - Version: conversion.StringValueToPointer(model.Version), - Options: &payloadOptions, + Version: model.Version.ValueString(), + Options: payloadOptions, }, nil } @@ -969,12 +969,12 @@ func toUpdatePayload(model *Model, acl []string, flavor *flavorModel, storage *s return &mongodbflex.PartialUpdateInstancePayload{ Acl: &mongodbflex.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), Storage: &mongodbflex.Storage{ Class: conversion.StringValueToPointer(storage.Class), Size: conversion.Int64ValueToPointer(storage.Size), @@ -999,29 +999,29 @@ func toUpdateBackupScheduleOptionsPayload(ctx context.Context, model *Model, con backupSchedule := conversion.StringValueToPointer(model.BackupSchedule) - snapshotRetentionDays := conversion.Int64ValueToPointer(configuredOptions.SnapshotRetentionDays) + snapshotRetentionDays := conversion.Int32ValueToPointer(configuredOptions.SnapshotRetentionDays) if snapshotRetentionDays == nil { - snapshotRetentionDays = conversion.Int64ValueToPointer(currOptions.SnapshotRetentionDays) + snapshotRetentionDays = conversion.Int32ValueToPointer(currOptions.SnapshotRetentionDays) } - dailySnapshotRetentionDays := conversion.Int64ValueToPointer(configuredOptions.DailySnapshotRetentionDays) + dailySnapshotRetentionDays := conversion.Int32ValueToPointer(configuredOptions.DailySnapshotRetentionDays) if dailySnapshotRetentionDays == nil { - dailySnapshotRetentionDays = conversion.Int64ValueToPointer(currOptions.DailySnapshotRetentionDays) + dailySnapshotRetentionDays = conversion.Int32ValueToPointer(currOptions.DailySnapshotRetentionDays) } - weeklySnapshotRetentionWeeks := conversion.Int64ValueToPointer(configuredOptions.WeeklySnapshotRetentionWeeks) + weeklySnapshotRetentionWeeks := conversion.Int32ValueToPointer(configuredOptions.WeeklySnapshotRetentionWeeks) if weeklySnapshotRetentionWeeks == nil { - weeklySnapshotRetentionWeeks = conversion.Int64ValueToPointer(currOptions.WeeklySnapshotRetentionWeeks) + weeklySnapshotRetentionWeeks = conversion.Int32ValueToPointer(currOptions.WeeklySnapshotRetentionWeeks) } - monthlySnapshotRetentionMonths := conversion.Int64ValueToPointer(configuredOptions.MonthlySnapshotRetentionMonths) + monthlySnapshotRetentionMonths := conversion.Int32ValueToPointer(configuredOptions.MonthlySnapshotRetentionMonths) if monthlySnapshotRetentionMonths == nil { - monthlySnapshotRetentionMonths = conversion.Int64ValueToPointer(currOptions.MonthlySnapshotRetentionMonths) + monthlySnapshotRetentionMonths = conversion.Int32ValueToPointer(currOptions.MonthlySnapshotRetentionMonths) } - pointInTimeWindowHours := conversion.Int64ValueToPointer(configuredOptions.PointInTimeWindowHours) + pointInTimeWindowHours := conversion.Int32ValueToPointer(configuredOptions.PointInTimeWindowHours) if pointInTimeWindowHours == nil { - pointInTimeWindowHours = conversion.Int64ValueToPointer(currOptions.PointInTimeWindowHours) + pointInTimeWindowHours = conversion.Int32ValueToPointer(currOptions.PointInTimeWindowHours) } return &mongodbflex.UpdateBackupSchedulePayload{ @@ -1036,7 +1036,8 @@ func toUpdateBackupScheduleOptionsPayload(ctx context.Context, model *Model, con } type mongoDBFlexClient interface { - ListFlavorsExecute(ctx context.Context, projectId, region string) (*mongodbflex.ListFlavorsResponse, error) + ListFlavors(ctx context.Context, projectId, region string) mongodbflex.ApiListFlavorsRequest + ListFlavorsExecute(r mongodbflex.ApiListFlavorsRequest) (*mongodbflex.ListFlavorsResponse, error) } func loadFlavorId(ctx context.Context, client mongoDBFlexClient, model *Model, flavor *flavorModel, region string) error { @@ -1046,17 +1047,18 @@ func loadFlavorId(ctx context.Context, client mongoDBFlexClient, model *Model, f if flavor == nil { return fmt.Errorf("nil flavor") } - cpu := conversion.Int64ValueToPointer(flavor.CPU) + cpu := conversion.Int32ValueToPointer(flavor.CPU) if cpu == nil { return fmt.Errorf("nil CPU") } - ram := conversion.Int64ValueToPointer(flavor.RAM) + ram := conversion.Int32ValueToPointer(flavor.RAM) if ram == nil { return fmt.Errorf("nil RAM") } projectId := model.ProjectId.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 mongodbflex flavors: %w", err) } @@ -1065,7 +1067,7 @@ func loadFlavorId(ctx context.Context, client mongoDBFlexClient, model *Model, f 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/mongodbflex/instance/resource_test.go b/stackit/internal/services/mongodbflex/instance/resource_test.go index 02acfbcf5..696e6901d 100644 --- a/stackit/internal/services/mongodbflex/instance/resource_test.go +++ b/stackit/internal/services/mongodbflex/instance/resource_test.go @@ -6,12 +6,13 @@ import ( "testing" "github.com/google/uuid" + "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" ) const ( @@ -26,9 +27,14 @@ var ( type mongoDBFlexClientMocked struct { returnError bool listFlavorsResp *mongodbflex.ListFlavorsResponse + listFlavorsReq mongodbflex.ApiListFlavorsRequest } -func (c *mongoDBFlexClientMocked) ListFlavorsExecute(_ context.Context, _, _ string) (*mongodbflex.ListFlavorsResponse, error) { +func (c *mongoDBFlexClientMocked) ListFlavors(_ context.Context, _, _ string) mongodbflex.ApiListFlavorsRequest { + return c.listFlavorsReq +} + +func (c *mongoDBFlexClientMocked) ListFlavorsExecute(_ mongodbflex.ApiListFlavorsRequest) (*mongodbflex.ListFlavorsResponse, error) { if c.returnError { return nil, fmt.Errorf("get flavors failed") } @@ -71,21 +77,21 @@ func TestMapFields(t *testing.T) { Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{ "id": types.StringNull(), "description": types.StringNull(), - "cpu": types.Int64Null(), - "ram": types.Int64Null(), + "cpu": types.Int32Null(), + "ram": types.Int32Null(), }), - Replicas: types.Int64Null(), + Replicas: types.Int32Null(), Storage: types.ObjectValueMust(storageTypes, map[string]attr.Value{ "class": types.StringNull(), "size": types.Int64Null(), }), Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringNull(), - "snapshot_retention_days": types.Int64Null(), - "daily_snapshot_retention_days": types.Int64Null(), - "weekly_snapshot_retention_weeks": types.Int64Null(), - "monthly_snapshot_retention_months": types.Int64Null(), - "point_in_time_window_hours": types.Int64Null(), + "snapshot_retention_days": types.Int32Null(), + "daily_snapshot_retention_days": types.Int32Null(), + "weekly_snapshot_retention_weeks": types.Int32Null(), + "monthly_snapshot_retention_months": types.Int32Null(), + "point_in_time_window_hours": types.Int32Null(), }), Version: types.StringNull(), Region: types.StringValue(testRegion), @@ -101,26 +107,26 @@ func TestMapFields(t *testing.T) { &mongodbflex.InstanceResponse{ Item: &mongodbflex.Instance{ Acl: &mongodbflex.ACL{ - Items: &[]string{ + Items: []string{ "ip1", "ip2", "", }, }, - BackupSchedule: new("schedule"), + BackupSchedule: utils.Ptr("schedule"), Flavor: &mongodbflex.Flavor{ - Cpu: new(int64(12)), - Description: new("description"), - Id: new("flavor_id"), - Memory: new(int64(34)), + Cpu: utils.Ptr(int32(12)), + Description: utils.Ptr("description"), + Id: utils.Ptr("flavor_id"), + Memory: utils.Ptr(int32(34)), }, - Id: new(instanceId), - Name: new("name"), - Replicas: new(int64(56)), - Status: mongodbflex.INSTANCESTATUS_READY.Ptr(), + Id: utils.Ptr(instanceId), + Name: utils.Ptr("name"), + Replicas: utils.Ptr(int32(56)), + Status: utils.Ptr("READY"), Storage: &mongodbflex.Storage{ - Class: new("class"), - Size: new(int64(78)), + Class: utils.Ptr("class"), + Size: utils.Ptr(int64(78)), }, Options: &map[string]string{ "type": "type", @@ -130,7 +136,7 @@ func TestMapFields(t *testing.T) { "monthlySnapshotRetentionMonths": "8", "pointInTimeWindowHours": "9", }, - Version: new("version"), + Version: utils.Ptr("version"), }, }, &flavorModel{}, @@ -151,21 +157,21 @@ func TestMapFields(t *testing.T) { Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{ "id": types.StringValue("flavor_id"), "description": types.StringValue("description"), - "cpu": types.Int64Value(12), - "ram": types.Int64Value(34), + "cpu": types.Int32Value(12), + "ram": types.Int32Value(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), }), Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringValue("type"), - "snapshot_retention_days": types.Int64Value(5), - "daily_snapshot_retention_days": types.Int64Value(6), - "weekly_snapshot_retention_weeks": types.Int64Value(7), - "monthly_snapshot_retention_months": types.Int64Value(8), - "point_in_time_window_hours": types.Int64Value(9), + "snapshot_retention_days": types.Int32Value(5), + "daily_snapshot_retention_days": types.Int32Value(6), + "weekly_snapshot_retention_weeks": types.Int32Value(7), + "monthly_snapshot_retention_months": types.Int32Value(8), + "point_in_time_window_hours": types.Int32Value(9), }), Region: types.StringValue(testRegion), Version: types.StringValue("version"), @@ -181,18 +187,18 @@ func TestMapFields(t *testing.T) { &mongodbflex.InstanceResponse{ Item: &mongodbflex.Instance{ Acl: &mongodbflex.ACL{ - Items: &[]string{ + Items: []string{ "ip1", "ip2", "", }, }, - BackupSchedule: new("schedule"), + BackupSchedule: utils.Ptr("schedule"), Flavor: nil, - Id: new(instanceId), - Name: new("name"), - Replicas: new(int64(56)), - Status: mongodbflex.INSTANCESTATUS_READY.Ptr(), + Id: utils.Ptr(instanceId), + Name: utils.Ptr("name"), + Replicas: utils.Ptr(int32(56)), + Status: utils.Ptr("READY"), Storage: nil, Options: &map[string]string{ "type": "type", @@ -202,12 +208,12 @@ func TestMapFields(t *testing.T) { "monthlySnapshotRetentionMonths": "8", "pointInTimeWindowHours": "9", }, - Version: new("version"), + Version: utils.Ptr("version"), }, }, &flavorModel{ - CPU: types.Int64Value(12), - RAM: types.Int64Value(34), + CPU: types.Int32Value(12), + RAM: types.Int32Value(34), }, &storageModel{ Class: types.StringValue("class"), @@ -231,21 +237,21 @@ func TestMapFields(t *testing.T) { Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{ "id": types.StringNull(), "description": types.StringNull(), - "cpu": types.Int64Value(12), - "ram": types.Int64Value(34), + "cpu": types.Int32Value(12), + "ram": types.Int32Value(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), }), Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringValue("type"), - "snapshot_retention_days": types.Int64Value(5), - "daily_snapshot_retention_days": types.Int64Value(6), - "weekly_snapshot_retention_weeks": types.Int64Value(7), - "monthly_snapshot_retention_months": types.Int64Value(8), - "point_in_time_window_hours": types.Int64Value(9), + "snapshot_retention_days": types.Int32Value(5), + "daily_snapshot_retention_days": types.Int32Value(6), + "weekly_snapshot_retention_weeks": types.Int32Value(7), + "monthly_snapshot_retention_months": types.Int32Value(8), + "point_in_time_window_hours": types.Int32Value(9), }), Region: types.StringValue(testRegion), Version: types.StringValue("version"), @@ -266,18 +272,18 @@ func TestMapFields(t *testing.T) { &mongodbflex.InstanceResponse{ Item: &mongodbflex.Instance{ Acl: &mongodbflex.ACL{ - Items: &[]string{ + Items: []string{ "", "ip1", "ip2", }, }, - BackupSchedule: new("schedule"), + BackupSchedule: utils.Ptr("schedule"), Flavor: nil, - Id: new(instanceId), - Name: new("name"), - Replicas: new(int64(56)), - Status: mongodbflex.INSTANCESTATUS_READY.Ptr(), + Id: utils.Ptr(instanceId), + Name: utils.Ptr("name"), + Replicas: utils.Ptr(int32(56)), + Status: utils.Ptr("READY"), Storage: nil, Options: &map[string]string{ "type": "type", @@ -287,12 +293,12 @@ func TestMapFields(t *testing.T) { "monthlySnapshotRetentionMonths": "8", "pointInTimeWindowHours": "9", }, - Version: new("version"), + Version: utils.Ptr("version"), }, }, &flavorModel{ - CPU: types.Int64Value(12), - RAM: types.Int64Value(34), + CPU: types.Int32Value(12), + RAM: types.Int32Value(34), }, &storageModel{ Class: types.StringValue("class"), @@ -316,21 +322,21 @@ func TestMapFields(t *testing.T) { Flavor: types.ObjectValueMust(flavorTypes, map[string]attr.Value{ "id": types.StringNull(), "description": types.StringNull(), - "cpu": types.Int64Value(12), - "ram": types.Int64Value(34), + "cpu": types.Int32Value(12), + "ram": types.Int32Value(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), }), Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringValue("type"), - "snapshot_retention_days": types.Int64Value(5), - "daily_snapshot_retention_days": types.Int64Value(6), - "weekly_snapshot_retention_weeks": types.Int64Value(7), - "monthly_snapshot_retention_months": types.Int64Value(8), - "point_in_time_window_hours": types.Int64Value(9), + "snapshot_retention_days": types.Int32Value(5), + "daily_snapshot_retention_days": types.Int32Value(6), + "weekly_snapshot_retention_weeks": types.Int32Value(7), + "monthly_snapshot_retention_months": types.Int32Value(8), + "point_in_time_window_hours": types.Int32Value(9), }), Region: types.StringValue(testRegion), Version: types.StringValue("version"), @@ -402,11 +408,11 @@ func TestMapOptions(t *testing.T) { &Model{ Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringNull(), - "snapshot_retention_days": types.Int64Null(), - "daily_snapshot_retention_days": types.Int64Null(), - "weekly_snapshot_retention_weeks": types.Int64Null(), - "monthly_snapshot_retention_months": types.Int64Null(), - "point_in_time_window_hours": types.Int64Null(), + "snapshot_retention_days": types.Int32Null(), + "daily_snapshot_retention_days": types.Int32Null(), + "weekly_snapshot_retention_weeks": types.Int32Null(), + "monthly_snapshot_retention_months": types.Int32Null(), + "point_in_time_window_hours": types.Int32Null(), }), }, true, @@ -418,20 +424,20 @@ func TestMapOptions(t *testing.T) { Type: types.StringValue("type"), }, &mongodbflex.BackupSchedule{ - SnapshotRetentionDays: new(int64(1)), - DailySnapshotRetentionDays: new(int64(2)), - WeeklySnapshotRetentionWeeks: new(int64(3)), - MonthlySnapshotRetentionMonths: new(int64(4)), - PointInTimeWindowHours: new(int64(5)), + SnapshotRetentionDays: utils.Ptr(int32(1)), + DailySnapshotRetentionDays: utils.Ptr(int32(2)), + WeeklySnapshotRetentionWeeks: utils.Ptr(int32(3)), + MonthlySnapshotRetentionMonths: utils.Ptr(int32(4)), + PointInTimeWindowHours: utils.Ptr(int32(5)), }, &Model{ Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringValue("type"), - "snapshot_retention_days": types.Int64Value(1), - "daily_snapshot_retention_days": types.Int64Value(2), - "weekly_snapshot_retention_weeks": types.Int64Value(3), - "monthly_snapshot_retention_months": types.Int64Value(4), - "point_in_time_window_hours": types.Int64Value(5), + "snapshot_retention_days": types.Int32Value(1), + "daily_snapshot_retention_days": types.Int32Value(2), + "weekly_snapshot_retention_weeks": types.Int32Value(3), + "monthly_snapshot_retention_months": types.Int32Value(4), + "point_in_time_window_hours": types.Int32Value(5), }), }, true, @@ -475,11 +481,11 @@ func TestToCreatePayload(t *testing.T) { &storageModel{}, &optionsModel{}, &mongodbflex.CreateInstancePayload{ - Acl: &mongodbflex.CreateInstancePayloadAcl{ - Items: &[]string{}, + Acl: mongodbflex.ACL{ + Items: []string{}, }, - Storage: &mongodbflex.Storage{}, - Options: &map[string]string{}, + Storage: mongodbflex.Storage{}, + Options: map[string]string{}, }, true, }, @@ -488,7 +494,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{ @@ -506,22 +512,22 @@ func TestToCreatePayload(t *testing.T) { Type: types.StringValue("type"), }, &mongodbflex.CreateInstancePayload{ - Acl: &mongodbflex.CreateInstancePayloadAcl{ - Items: &[]string{ + Acl: mongodbflex.ACL{ + Items: []string{ "ip_1", "ip_2", }, }, - BackupSchedule: new("schedule"), - FlavorId: new("flavor_id"), - Name: new("name"), - Replicas: new(int64(12)), - Storage: &mongodbflex.Storage{ - Class: new("class"), - Size: new(int64(34)), + BackupSchedule: "schedule", + FlavorId: "flavor_id", + Name: "name", + Replicas: int32(12), + Storage: mongodbflex.Storage{ + Class: utils.Ptr("class"), + Size: utils.Ptr(int64(34)), }, - Options: &map[string]string{"type": "type"}, - Version: new("version"), + Options: map[string]string{"type": "type"}, + Version: "version", }, true, }, @@ -530,7 +536,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{ @@ -547,21 +553,21 @@ func TestToCreatePayload(t *testing.T) { Type: types.StringNull(), }, &mongodbflex.CreateInstancePayload{ - Acl: &mongodbflex.CreateInstancePayloadAcl{ - Items: &[]string{ + Acl: mongodbflex.ACL{ + Items: []string{ "", }, }, - BackupSchedule: nil, - FlavorId: nil, - Name: nil, - Replicas: new(int64(2123456789)), - Storage: &mongodbflex.Storage{ + BackupSchedule: "", + FlavorId: "", + Name: "", + Replicas: int32(2123456789), + Storage: mongodbflex.Storage{ Class: nil, Size: nil, }, - Options: &map[string]string{}, - Version: nil, + Options: map[string]string{}, + Version: "", }, true, }, @@ -655,7 +661,7 @@ func TestToUpdatePayload(t *testing.T) { &optionsModel{}, &mongodbflex.PartialUpdateInstancePayload{ Acl: &mongodbflex.ACL{ - Items: &[]string{}, + Items: []string{}, }, Storage: &mongodbflex.Storage{}, Options: &map[string]string{}, @@ -667,7 +673,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{ @@ -686,21 +692,21 @@ func TestToUpdatePayload(t *testing.T) { }, &mongodbflex.PartialUpdateInstancePayload{ Acl: &mongodbflex.ACL{ - Items: &[]string{ + Items: []string{ "ip_1", "ip_2", }, }, - BackupSchedule: new("schedule"), - FlavorId: new("flavor_id"), - Name: new("name"), - Replicas: new(int64(12)), + BackupSchedule: utils.Ptr("schedule"), + FlavorId: utils.Ptr("flavor_id"), + Name: utils.Ptr("name"), + Replicas: utils.Ptr(int32(12)), Storage: &mongodbflex.Storage{ - Class: new("class"), - Size: new(int64(34)), + Class: utils.Ptr("class"), + Size: utils.Ptr(int64(34)), }, Options: &map[string]string{"type": "type"}, - Version: new("version"), + Version: utils.Ptr("version"), }, true, }, @@ -709,7 +715,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{ @@ -727,14 +733,14 @@ func TestToUpdatePayload(t *testing.T) { }, &mongodbflex.PartialUpdateInstancePayload{ Acl: &mongodbflex.ACL{ - Items: &[]string{ + Items: []string{ "", }, }, BackupSchedule: nil, FlavorId: nil, Name: nil, - Replicas: new(int64(2123456789)), + Replicas: utils.Ptr(int32(2123456789)), Storage: &mongodbflex.Storage{ Class: nil, Size: nil, @@ -842,27 +848,27 @@ func TestToUpdateBackupScheduleOptionsPayload(t *testing.T) { BackupSchedule: types.StringValue("schedule"), Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringValue("type"), - "snapshot_retention_days": types.Int64Value(1), - "daily_snapshot_retention_days": types.Int64Value(2), - "weekly_snapshot_retention_weeks": types.Int64Value(3), - "monthly_snapshot_retention_months": types.Int64Value(4), - "point_in_time_window_hours": types.Int64Value(5), + "snapshot_retention_days": types.Int32Value(1), + "daily_snapshot_retention_days": types.Int32Value(2), + "weekly_snapshot_retention_weeks": types.Int32Value(3), + "monthly_snapshot_retention_months": types.Int32Value(4), + "point_in_time_window_hours": types.Int32Value(5), }), }, &optionsModel{ - SnapshotRetentionDays: types.Int64Value(6), - DailySnapshotRetentionDays: types.Int64Value(7), - WeeklySnapshotRetentionWeeks: types.Int64Value(8), - MonthlySnapshotRetentionMonths: types.Int64Value(9), - PointInTimeWindowHours: types.Int64Value(10), + SnapshotRetentionDays: types.Int32Value(6), + DailySnapshotRetentionDays: types.Int32Value(7), + WeeklySnapshotRetentionWeeks: types.Int32Value(8), + MonthlySnapshotRetentionMonths: types.Int32Value(9), + PointInTimeWindowHours: types.Int32Value(10), }, &mongodbflex.UpdateBackupSchedulePayload{ - BackupSchedule: new("schedule"), - SnapshotRetentionDays: new(int64(6)), - DailySnapshotRetentionDays: new(int64(7)), - WeeklySnapshotRetentionWeeks: new(int64(8)), - MonthlySnapshotRetentionMonths: new(int64(9)), - PointInTimeWindowHours: new(int64(10)), + BackupSchedule: utils.Ptr("schedule"), + SnapshotRetentionDays: utils.Ptr(int32(6)), + DailySnapshotRetentionDays: utils.Ptr(int32(7)), + WeeklySnapshotRetentionWeeks: utils.Ptr(int32(8)), + MonthlySnapshotRetentionMonths: utils.Ptr(int32(9)), + PointInTimeWindowHours: utils.Ptr(int32(10)), }, true, }, @@ -872,27 +878,27 @@ func TestToUpdateBackupScheduleOptionsPayload(t *testing.T) { BackupSchedule: types.StringValue("schedule"), Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ "type": types.StringValue("type"), - "snapshot_retention_days": types.Int64Value(1), - "daily_snapshot_retention_days": types.Int64Value(2), - "weekly_snapshot_retention_weeks": types.Int64Value(3), - "monthly_snapshot_retention_months": types.Int64Value(4), - "point_in_time_window_hours": types.Int64Value(5), + "snapshot_retention_days": types.Int32Value(1), + "daily_snapshot_retention_days": types.Int32Value(2), + "weekly_snapshot_retention_weeks": types.Int32Value(3), + "monthly_snapshot_retention_months": types.Int32Value(4), + "point_in_time_window_hours": types.Int32Value(5), }), }, &optionsModel{ - SnapshotRetentionDays: types.Int64Value(6), - DailySnapshotRetentionDays: types.Int64Value(7), - WeeklySnapshotRetentionWeeks: types.Int64Null(), - MonthlySnapshotRetentionMonths: types.Int64Null(), - PointInTimeWindowHours: types.Int64Null(), + SnapshotRetentionDays: types.Int32Value(6), + DailySnapshotRetentionDays: types.Int32Value(7), + WeeklySnapshotRetentionWeeks: types.Int32Null(), + MonthlySnapshotRetentionMonths: types.Int32Null(), + PointInTimeWindowHours: types.Int32Null(), }, &mongodbflex.UpdateBackupSchedulePayload{ - BackupSchedule: new("schedule"), - SnapshotRetentionDays: new(int64(6)), - DailySnapshotRetentionDays: new(int64(7)), - WeeklySnapshotRetentionWeeks: new(int64(3)), - MonthlySnapshotRetentionMonths: new(int64(4)), - PointInTimeWindowHours: new(int64(5)), + BackupSchedule: utils.Ptr("schedule"), + SnapshotRetentionDays: utils.Ptr(int32(6)), + DailySnapshotRetentionDays: utils.Ptr(int32(7)), + WeeklySnapshotRetentionWeeks: utils.Ptr(int32(3)), + MonthlySnapshotRetentionMonths: utils.Ptr(int32(4)), + PointInTimeWindowHours: utils.Ptr(int32(5)), }, true, }, @@ -902,11 +908,11 @@ func TestToUpdateBackupScheduleOptionsPayload(t *testing.T) { BackupSchedule: types.StringNull(), }, &optionsModel{ - SnapshotRetentionDays: types.Int64Null(), - DailySnapshotRetentionDays: types.Int64Null(), - WeeklySnapshotRetentionWeeks: types.Int64Null(), - MonthlySnapshotRetentionMonths: types.Int64Null(), - PointInTimeWindowHours: types.Int64Null(), + SnapshotRetentionDays: types.Int32Null(), + DailySnapshotRetentionDays: types.Int32Null(), + WeeklySnapshotRetentionWeeks: types.Int32Null(), + MonthlySnapshotRetentionMonths: types.Int32Null(), + PointInTimeWindowHours: types.Int32Null(), }, &mongodbflex.UpdateBackupSchedulePayload{ BackupSchedule: nil, @@ -950,24 +956,24 @@ func TestLoadFlavorId(t *testing.T) { { "ok_flavor", &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, &mongodbflex.ListFlavorsResponse{ - Flavors: &[]mongodbflex.InstanceFlavor{ + Flavors: []mongodbflex.InstanceFlavor{ { - Id: new("fid-1"), - Cpu: new(int64(2)), - Description: new("description"), - Memory: new(int64(8)), + Id: utils.Ptr("fid-1"), + Cpu: utils.Ptr(int32(2)), + Description: utils.Ptr("description"), + Memory: utils.Ptr(int32(8)), }, }, }, &flavorModel{ Id: types.StringValue("fid-1"), Description: types.StringValue("description"), - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, false, true, @@ -975,30 +981,30 @@ func TestLoadFlavorId(t *testing.T) { { "ok_flavor_2", &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, &mongodbflex.ListFlavorsResponse{ - Flavors: &[]mongodbflex.InstanceFlavor{ + Flavors: []mongodbflex.InstanceFlavor{ { - Id: new("fid-1"), - Cpu: new(int64(2)), - Description: new("description"), - Memory: new(int64(8)), + Id: utils.Ptr("fid-1"), + Cpu: utils.Ptr(int32(2)), + Description: utils.Ptr("description"), + Memory: utils.Ptr(int32(8)), }, { - Id: new("fid-2"), - Cpu: new(int64(1)), - Description: new("description"), - Memory: new(int64(4)), + Id: utils.Ptr("fid-2"), + Cpu: utils.Ptr(int32(1)), + Description: utils.Ptr("description"), + Memory: utils.Ptr(int32(4)), }, }, }, &flavorModel{ Id: types.StringValue("fid-1"), Description: types.StringValue("description"), - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, false, true, @@ -1006,28 +1012,28 @@ func TestLoadFlavorId(t *testing.T) { { "no_matching_flavor", &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, &mongodbflex.ListFlavorsResponse{ - Flavors: &[]mongodbflex.InstanceFlavor{ + Flavors: []mongodbflex.InstanceFlavor{ { - Id: new("fid-1"), - Cpu: new(int64(1)), - Description: new("description"), - Memory: new(int64(8)), + Id: utils.Ptr("fid-1"), + Cpu: utils.Ptr(int32(1)), + Description: utils.Ptr("description"), + Memory: utils.Ptr(int32(8)), }, { - Id: new("fid-2"), - Cpu: new(int64(1)), - Description: new("description"), - Memory: new(int64(4)), + Id: utils.Ptr("fid-2"), + Cpu: utils.Ptr(int32(1)), + Description: utils.Ptr("description"), + Memory: utils.Ptr(int32(4)), }, }, }, &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, false, false, @@ -1035,13 +1041,13 @@ func TestLoadFlavorId(t *testing.T) { { "nil_response", &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, &mongodbflex.ListFlavorsResponse{}, &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, false, false, @@ -1049,13 +1055,13 @@ func TestLoadFlavorId(t *testing.T) { { "error_response", &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, &mongodbflex.ListFlavorsResponse{}, &flavorModel{ - CPU: types.Int64Value(2), - RAM: types.Int64Value(8), + CPU: types.Int32Value(2), + RAM: types.Int32Value(8), }, true, false, diff --git a/stackit/internal/services/mongodbflex/mongodbflex_acc_test.go b/stackit/internal/services/mongodbflex/mongodbflex_acc_test.go index 8dcc28247..9260b8148 100644 --- a/stackit/internal/services/mongodbflex/mongodbflex_acc_test.go +++ b/stackit/internal/services/mongodbflex/mongodbflex_acc_test.go @@ -11,8 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/wait" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" + "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -312,22 +312,22 @@ func testAccCheckMongoDBFlexDestroy(s *terraform.State) error { instancesToDestroy = append(instancesToDestroy, instanceId) } - instancesResp, err := client.ListInstances(ctx, testutil.ProjectId, testutil.Region).Tag("").Execute() + instancesResp, err := client.DefaultAPI.ListInstances(ctx, testutil.ProjectId, testutil.Region).Tag("").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 utils.Contains(instancesToDestroy, *items[i].Id) { - err := client.DeleteInstanceExecute(ctx, testutil.ProjectId, *items[i].Id, testutil.Region) + err := client.DefaultAPI.DeleteInstance(ctx, testutil.ProjectId, *items[i].Id, testutil.Region).Execute() if err != nil { return fmt.Errorf("destroying instance %s during CheckDestroy: %w", *items[i].Id, err) } - _, err = wait.DeleteInstanceWaitHandler(ctx, client, testutil.ProjectId, *items[i].Id, testutil.Region).WaitWithContext(ctx) + _, err = wait.DeleteInstanceWaitHandler(ctx, client.DefaultAPI, testutil.ProjectId, *items[i].Id, testutil.Region).WaitWithContext(ctx) if err != nil { return fmt.Errorf("destroying instance %s during CheckDestroy: waiting for deletion %w", *items[i].Id, err) } diff --git a/stackit/internal/services/mongodbflex/mongodbflex_test.go b/stackit/internal/services/mongodbflex/mongodbflex_test.go index d3a1f8a08..a27ed34c4 100644 --- a/stackit/internal/services/mongodbflex/mongodbflex_test.go +++ b/stackit/internal/services/mongodbflex/mongodbflex_test.go @@ -8,7 +8,8 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" + "github.com/stackitcloud/stackit-sdk-go/core/utils" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -62,18 +63,18 @@ resource "stackit_mongodbflex_instance" "instance" { s.Reset( testutil.MockResponse{ Description: "ListFlavors", - ToJsonBody: &mongodbflex.ListFlavorsResponse{Flavors: &[]mongodbflex.InstanceFlavor{ + ToJsonBody: &mongodbflex.ListFlavorsResponse{Flavors: []mongodbflex.InstanceFlavor{ { - Description: new("flava-flav"), - Cpu: new(int64(2)), - Id: new("flavor-id"), - Memory: new(int64(4)), + Description: utils.Ptr("flava-flav"), + Cpu: utils.Ptr(int32(2)), + Id: utils.Ptr("flavor-id"), + Memory: utils.Ptr(int32(4)), }, }}, }, testutil.MockResponse{ Description: "create instance", - ToJsonBody: &mongodbflex.CreateInstanceResponse{Id: new(instanceId)}, + ToJsonBody: &mongodbflex.CreateInstanceResponse{Id: utils.Ptr(instanceId)}, }, testutil.MockResponse{Description: "create waiter", StatusCode: http.StatusInternalServerError}, ) @@ -135,7 +136,7 @@ resource "stackit_mongodbflex_user" "user" { s.Reset( testutil.MockResponse{ Description: "create user", - ToJsonBody: &mongodbflex.CreateUserResponse{Item: &mongodbflex.User{Id: new(userId)}}, + ToJsonBody: &mongodbflex.CreateUserResponse{Item: &mongodbflex.User{Id: utils.Ptr(userId)}}, }, testutil.MockResponse{Description: "failing waiter", StatusCode: http.StatusInternalServerError}, ) diff --git a/stackit/internal/services/mongodbflex/user/datasource.go b/stackit/internal/services/mongodbflex/user/datasource.go index d9defbb10..703dae046 100644 --- a/stackit/internal/services/mongodbflex/user/datasource.go +++ b/stackit/internal/services/mongodbflex/user/datasource.go @@ -18,7 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -158,7 +158,7 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r ctx = tflog.SetField(ctx, "instance_id", instanceId) ctx = tflog.SetField(ctx, "user_id", userId) - recordSetResp, err := d.client.GetUser(ctx, projectId, instanceId, userId, region).Execute() + recordSetResp, err := d.client.DefaultAPI.GetUser(ctx, projectId, instanceId, userId, region).Execute() if err != nil { utils.LogError( ctx, @@ -218,7 +218,7 @@ func mapDataSourceFields(userResp *mongodbflex.GetUserResponse, model *DataSourc 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/mongodbflex/user/datasource_test.go b/stackit/internal/services/mongodbflex/user/datasource_test.go index d3df40872..61bd342b5 100644 --- a/stackit/internal/services/mongodbflex/user/datasource_test.go +++ b/stackit/internal/services/mongodbflex/user/datasource_test.go @@ -7,7 +7,8 @@ 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/mongodbflex" + "github.com/stackitcloud/stackit-sdk-go/core/utils" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" ) func TestMapDataSourceFields(t *testing.T) { @@ -41,15 +42,15 @@ func TestMapDataSourceFields(t *testing.T) { "simple_values", &mongodbflex.GetUserResponse{ Item: &mongodbflex.InstanceResponseUser{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", "", }, - Username: new("username"), - Database: new("database"), - Host: new("host"), - Port: new(int64(1234)), + Username: utils.Ptr("username"), + Database: utils.Ptr("database"), + Host: utils.Ptr("host"), + Port: utils.Ptr(int64(1234)), }, }, testRegion, @@ -74,12 +75,12 @@ func TestMapDataSourceFields(t *testing.T) { "null_fields_and_int_conversions", &mongodbflex.GetUserResponse{ Item: &mongodbflex.InstanceResponseUser{ - Id: new(userId), - Roles: &[]string{}, + Id: utils.Ptr(userId), + Roles: []string{}, Username: nil, Database: nil, Host: nil, - Port: new(int64(2123456789)), + Port: utils.Ptr(int64(2123456789)), }, }, testRegion, diff --git a/stackit/internal/services/mongodbflex/user/resource.go b/stackit/internal/services/mongodbflex/user/resource.go index 7c11d2d2d..603034913 100644 --- a/stackit/internal/services/mongodbflex/user/resource.go +++ b/stackit/internal/services/mongodbflex/user/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/mongodbflex" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -247,7 +247,7 @@ func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, r return } // Create new user - userResp, err := r.client.CreateUser(ctx, projectId, instanceId, region).CreateUserPayload(*payload).Execute() + userResp, err := r.client.DefaultAPI.CreateUser(ctx, projectId, instanceId, region).CreateUserPayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err)) return @@ -305,7 +305,7 @@ func (r *userResource) Read(ctx context.Context, req resource.ReadRequest, resp ctx = tflog.SetField(ctx, "instance_id", instanceId) ctx = tflog.SetField(ctx, "user_id", userId) - recordSetResp, err := r.client.GetUser(ctx, projectId, instanceId, userId, region).Execute() + recordSetResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, instanceId, userId, region).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 { @@ -380,7 +380,7 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r } // Update existing instance - err = r.client.UpdateUser(ctx, projectId, instanceId, userId, region).UpdateUserPayload(*payload).Execute() + err = r.client.DefaultAPI.UpdateUser(ctx, projectId, instanceId, userId, region).UpdateUserPayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", err.Error()) return @@ -388,7 +388,7 @@ func (r *userResource) Update(ctx context.Context, req resource.UpdateRequest, r ctx = core.LogResponse(ctx) - userResp, err := r.client.GetUser(ctx, projectId, instanceId, userId, region).Execute() + userResp, err := r.client.DefaultAPI.GetUser(ctx, projectId, instanceId, userId, region).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating user", fmt.Sprintf("Calling API: %v", err)) return @@ -432,7 +432,7 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r ctx = tflog.SetField(ctx, "user_id", userId) // Delete user - err := r.client.DeleteUser(ctx, projectId, instanceId, userId, region).Execute() + err := r.client.DefaultAPI.DeleteUser(ctx, projectId, instanceId, userId, region).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting user", fmt.Sprintf("Calling API: %v", err)) return @@ -496,7 +496,7 @@ func mapFieldsCreate(userResp *mongodbflex.CreateUserResponse, model *Model, reg 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) @@ -538,7 +538,7 @@ func mapFields(userResp *mongodbflex.GetUserResponse, model *Model, region strin 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) @@ -561,9 +561,9 @@ func toCreatePayload(model *Model, roles []string) (*mongodbflex.CreateUserPaylo } return &mongodbflex.CreateUserPayload{ - Roles: &roles, + Roles: roles, Username: conversion.StringValueToPointer(model.Username), - Database: conversion.StringValueToPointer(model.Database), + Database: model.Database.ValueString(), }, nil } @@ -576,7 +576,7 @@ func toUpdatePayload(model *Model, roles []string) (*mongodbflex.UpdateUserPaylo } return &mongodbflex.UpdateUserPayload{ - Roles: &roles, - Database: conversion.StringValueToPointer(model.Database), + Roles: roles, + Database: model.Database.ValueString(), }, nil } diff --git a/stackit/internal/services/mongodbflex/user/resource_test.go b/stackit/internal/services/mongodbflex/user/resource_test.go index 5081f11af..3df36b909 100644 --- a/stackit/internal/services/mongodbflex/user/resource_test.go +++ b/stackit/internal/services/mongodbflex/user/resource_test.go @@ -5,11 +5,12 @@ import ( "testing" "github.com/google/uuid" + "github.com/stackitcloud/stackit-sdk-go/core/utils" "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/mongodbflex" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" ) const ( @@ -34,8 +35,8 @@ func TestMapFieldsCreate(t *testing.T) { "default_values", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: new(userId), - Password: new(""), + Id: utils.Ptr(userId), + Password: utils.Ptr(""), }, }, testRegion, @@ -59,18 +60,18 @@ func TestMapFieldsCreate(t *testing.T) { "simple_values", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: new(userId), - Roles: &[]string{ + Id: utils.Ptr(userId), + Roles: []string{ "role_1", "role_2", "", }, - Username: new("username"), - Database: new("database"), - Password: new("password"), - Host: new("host"), - Port: new(int64(1234)), - Uri: new("uri"), + Username: utils.Ptr("username"), + Database: utils.Ptr("database"), + Password: utils.Ptr("password"), + Host: utils.Ptr("host"), + Port: utils.Ptr(int64(1234)), + Uri: utils.Ptr("uri"), }, }, testRegion, @@ -98,13 +99,13 @@ func TestMapFieldsCreate(t *testing.T) { "null_fields_and_int_conversions", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: new(userId), - Roles: &[]string{}, + Id: utils.Ptr(userId), + Roles: []string{}, Username: nil, Database: nil, - Password: new(""), + Password: utils.Ptr(""), Host: nil, - Port: new(int64(2123456789)), + Port: utils.Ptr(int64(2123456789)), Uri: nil, }, }, @@ -152,7 +153,7 @@ func TestMapFieldsCreate(t *testing.T) { "no_password", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: new(userId), + Id: utils.Ptr(userId), }, }, testRegion, @@ -215,15 +216,15 @@ func TestMapFields(t *testing.T) { "simple_values", &mongodbflex.GetUserResponse{ Item: &mongodbflex.InstanceResponseUser{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", "", }, - Username: new("username"), - Database: new("database"), - Host: new("host"), - Port: new(int64(1234)), + Username: utils.Ptr("username"), + Database: utils.Ptr("database"), + Host: utils.Ptr("host"), + Port: utils.Ptr(int64(1234)), }, }, testRegion, @@ -249,12 +250,12 @@ func TestMapFields(t *testing.T) { "null_fields_and_int_conversions", &mongodbflex.GetUserResponse{ Item: &mongodbflex.InstanceResponseUser{ - Id: new(userId), - Roles: &[]string{}, + Id: utils.Ptr(userId), + Roles: []string{}, Username: nil, Database: nil, Host: nil, - Port: new(int64(2123456789)), + Port: utils.Ptr(int64(2123456789)), }, }, testRegion, @@ -333,9 +334,9 @@ func TestToCreatePayload(t *testing.T) { &Model{}, []string{}, &mongodbflex.CreateUserPayload{ - Roles: &[]string{}, + Roles: []string{}, Username: nil, - Database: nil, + Database: "", }, true, }, @@ -350,12 +351,12 @@ func TestToCreatePayload(t *testing.T) { "role_2", }, &mongodbflex.CreateUserPayload{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", }, - Username: new("username"), - Database: new("database"), + Username: utils.Ptr("username"), + Database: "database", }, true, }, @@ -369,11 +370,11 @@ func TestToCreatePayload(t *testing.T) { "", }, &mongodbflex.CreateUserPayload{ - Roles: &[]string{ + Roles: []string{ "", }, Username: nil, - Database: nil, + Database: "", }, true, }, @@ -424,8 +425,8 @@ func TestToUpdatePayload(t *testing.T) { &Model{}, []string{}, &mongodbflex.UpdateUserPayload{ - Roles: &[]string{}, - Database: nil, + Roles: []string{}, + Database: "", }, true, }, @@ -440,11 +441,11 @@ func TestToUpdatePayload(t *testing.T) { "role_2", }, &mongodbflex.UpdateUserPayload{ - Roles: &[]string{ + Roles: []string{ "role_1", "role_2", }, - Database: new("database"), + Database: "database", }, true, }, @@ -458,10 +459,10 @@ func TestToUpdatePayload(t *testing.T) { "", }, &mongodbflex.UpdateUserPayload{ - Roles: &[]string{ + Roles: []string{ "", }, - Database: nil, + Database: "", }, true, }, diff --git a/stackit/internal/services/mongodbflex/utils/util.go b/stackit/internal/services/mongodbflex/utils/util.go index e1c805c18..3ed8ff3e2 100644 --- a/stackit/internal/services/mongodbflex/utils/util.go +++ b/stackit/internal/services/mongodbflex/utils/util.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) diff --git a/stackit/internal/services/mongodbflex/utils/util_test.go b/stackit/internal/services/mongodbflex/utils/util_test.go index d268d9afb..16933efbd 100644 --- a/stackit/internal/services/mongodbflex/utils/util_test.go +++ b/stackit/internal/services/mongodbflex/utils/util_test.go @@ -9,7 +9,7 @@ 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/mongodbflex" + mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) From 19ea504b556194771b7645eb0669582a2299411b Mon Sep 17 00:00:00 2001 From: GokceGK Date: Tue, 7 Apr 2026 14:36:55 +0200 Subject: [PATCH 2/2] add back changes from the pr #1334 --- .../mongodbflex/instance/resource_test.go | 143 +++++++++--------- .../services/mongodbflex/mongodbflex_test.go | 13 +- .../mongodbflex/user/datasource_test.go | 13 +- .../mongodbflex/user/resource_test.go | 41 +++-- 4 files changed, 103 insertions(+), 107 deletions(-) diff --git a/stackit/internal/services/mongodbflex/instance/resource_test.go b/stackit/internal/services/mongodbflex/instance/resource_test.go index 696e6901d..bddc5a37c 100644 --- a/stackit/internal/services/mongodbflex/instance/resource_test.go +++ b/stackit/internal/services/mongodbflex/instance/resource_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -113,20 +112,20 @@ func TestMapFields(t *testing.T) { "", }, }, - BackupSchedule: utils.Ptr("schedule"), + BackupSchedule: new("schedule"), Flavor: &mongodbflex.Flavor{ - Cpu: utils.Ptr(int32(12)), - Description: utils.Ptr("description"), - Id: utils.Ptr("flavor_id"), - Memory: utils.Ptr(int32(34)), + Cpu: new(int32(12)), + Description: new("description"), + Id: new("flavor_id"), + Memory: new(int32(34)), }, - Id: utils.Ptr(instanceId), - Name: utils.Ptr("name"), - Replicas: utils.Ptr(int32(56)), - Status: utils.Ptr("READY"), + Id: new(instanceId), + Name: new("name"), + Replicas: new(int32(56)), + Status: new("READY"), Storage: &mongodbflex.Storage{ - Class: utils.Ptr("class"), - Size: utils.Ptr(int64(78)), + Class: new("class"), + Size: new(int64(78)), }, Options: &map[string]string{ "type": "type", @@ -136,7 +135,7 @@ func TestMapFields(t *testing.T) { "monthlySnapshotRetentionMonths": "8", "pointInTimeWindowHours": "9", }, - Version: utils.Ptr("version"), + Version: new("version"), }, }, &flavorModel{}, @@ -193,12 +192,12 @@ func TestMapFields(t *testing.T) { "", }, }, - BackupSchedule: utils.Ptr("schedule"), + BackupSchedule: new("schedule"), Flavor: nil, - Id: utils.Ptr(instanceId), - Name: utils.Ptr("name"), - Replicas: utils.Ptr(int32(56)), - Status: utils.Ptr("READY"), + Id: new(instanceId), + Name: new("name"), + Replicas: new(int32(56)), + Status: new("READY"), Storage: nil, Options: &map[string]string{ "type": "type", @@ -208,7 +207,7 @@ func TestMapFields(t *testing.T) { "monthlySnapshotRetentionMonths": "8", "pointInTimeWindowHours": "9", }, - Version: utils.Ptr("version"), + Version: new("version"), }, }, &flavorModel{ @@ -278,12 +277,12 @@ func TestMapFields(t *testing.T) { "ip2", }, }, - BackupSchedule: utils.Ptr("schedule"), + BackupSchedule: new("schedule"), Flavor: nil, - Id: utils.Ptr(instanceId), - Name: utils.Ptr("name"), - Replicas: utils.Ptr(int32(56)), - Status: utils.Ptr("READY"), + Id: new(instanceId), + Name: new("name"), + Replicas: new(int32(56)), + Status: new("READY"), Storage: nil, Options: &map[string]string{ "type": "type", @@ -293,7 +292,7 @@ func TestMapFields(t *testing.T) { "monthlySnapshotRetentionMonths": "8", "pointInTimeWindowHours": "9", }, - Version: utils.Ptr("version"), + Version: new("version"), }, }, &flavorModel{ @@ -424,11 +423,11 @@ func TestMapOptions(t *testing.T) { Type: types.StringValue("type"), }, &mongodbflex.BackupSchedule{ - SnapshotRetentionDays: utils.Ptr(int32(1)), - DailySnapshotRetentionDays: utils.Ptr(int32(2)), - WeeklySnapshotRetentionWeeks: utils.Ptr(int32(3)), - MonthlySnapshotRetentionMonths: utils.Ptr(int32(4)), - PointInTimeWindowHours: utils.Ptr(int32(5)), + SnapshotRetentionDays: new(int32(1)), + DailySnapshotRetentionDays: new(int32(2)), + WeeklySnapshotRetentionWeeks: new(int32(3)), + MonthlySnapshotRetentionMonths: new(int32(4)), + PointInTimeWindowHours: new(int32(5)), }, &Model{ Options: types.ObjectValueMust(optionsTypes, map[string]attr.Value{ @@ -523,8 +522,8 @@ func TestToCreatePayload(t *testing.T) { Name: "name", Replicas: int32(12), Storage: mongodbflex.Storage{ - Class: utils.Ptr("class"), - Size: utils.Ptr(int64(34)), + Class: new("class"), + Size: new(int64(34)), }, Options: map[string]string{"type": "type"}, Version: "version", @@ -697,16 +696,16 @@ func TestToUpdatePayload(t *testing.T) { "ip_2", }, }, - BackupSchedule: utils.Ptr("schedule"), - FlavorId: utils.Ptr("flavor_id"), - Name: utils.Ptr("name"), - Replicas: utils.Ptr(int32(12)), + BackupSchedule: new("schedule"), + FlavorId: new("flavor_id"), + Name: new("name"), + Replicas: new(int32(12)), Storage: &mongodbflex.Storage{ - Class: utils.Ptr("class"), - Size: utils.Ptr(int64(34)), + Class: new("class"), + Size: new(int64(34)), }, Options: &map[string]string{"type": "type"}, - Version: utils.Ptr("version"), + Version: new("version"), }, true, }, @@ -740,7 +739,7 @@ func TestToUpdatePayload(t *testing.T) { BackupSchedule: nil, FlavorId: nil, Name: nil, - Replicas: utils.Ptr(int32(2123456789)), + Replicas: new(int32(2123456789)), Storage: &mongodbflex.Storage{ Class: nil, Size: nil, @@ -863,12 +862,12 @@ func TestToUpdateBackupScheduleOptionsPayload(t *testing.T) { PointInTimeWindowHours: types.Int32Value(10), }, &mongodbflex.UpdateBackupSchedulePayload{ - BackupSchedule: utils.Ptr("schedule"), - SnapshotRetentionDays: utils.Ptr(int32(6)), - DailySnapshotRetentionDays: utils.Ptr(int32(7)), - WeeklySnapshotRetentionWeeks: utils.Ptr(int32(8)), - MonthlySnapshotRetentionMonths: utils.Ptr(int32(9)), - PointInTimeWindowHours: utils.Ptr(int32(10)), + BackupSchedule: new("schedule"), + SnapshotRetentionDays: new(int32(6)), + DailySnapshotRetentionDays: new(int32(7)), + WeeklySnapshotRetentionWeeks: new(int32(8)), + MonthlySnapshotRetentionMonths: new(int32(9)), + PointInTimeWindowHours: new(int32(10)), }, true, }, @@ -893,12 +892,12 @@ func TestToUpdateBackupScheduleOptionsPayload(t *testing.T) { PointInTimeWindowHours: types.Int32Null(), }, &mongodbflex.UpdateBackupSchedulePayload{ - BackupSchedule: utils.Ptr("schedule"), - SnapshotRetentionDays: utils.Ptr(int32(6)), - DailySnapshotRetentionDays: utils.Ptr(int32(7)), - WeeklySnapshotRetentionWeeks: utils.Ptr(int32(3)), - MonthlySnapshotRetentionMonths: utils.Ptr(int32(4)), - PointInTimeWindowHours: utils.Ptr(int32(5)), + BackupSchedule: new("schedule"), + SnapshotRetentionDays: new(int32(6)), + DailySnapshotRetentionDays: new(int32(7)), + WeeklySnapshotRetentionWeeks: new(int32(3)), + MonthlySnapshotRetentionMonths: new(int32(4)), + PointInTimeWindowHours: new(int32(5)), }, true, }, @@ -962,10 +961,10 @@ func TestLoadFlavorId(t *testing.T) { &mongodbflex.ListFlavorsResponse{ Flavors: []mongodbflex.InstanceFlavor{ { - Id: utils.Ptr("fid-1"), - Cpu: utils.Ptr(int32(2)), - Description: utils.Ptr("description"), - Memory: utils.Ptr(int32(8)), + Id: new("fid-1"), + Cpu: new(int32(2)), + Description: new("description"), + Memory: new(int32(8)), }, }, }, @@ -987,16 +986,16 @@ func TestLoadFlavorId(t *testing.T) { &mongodbflex.ListFlavorsResponse{ Flavors: []mongodbflex.InstanceFlavor{ { - Id: utils.Ptr("fid-1"), - Cpu: utils.Ptr(int32(2)), - Description: utils.Ptr("description"), - Memory: utils.Ptr(int32(8)), + Id: new("fid-1"), + Cpu: new(int32(2)), + Description: new("description"), + Memory: new(int32(8)), }, { - Id: utils.Ptr("fid-2"), - Cpu: utils.Ptr(int32(1)), - Description: utils.Ptr("description"), - Memory: utils.Ptr(int32(4)), + Id: new("fid-2"), + Cpu: new(int32(1)), + Description: new("description"), + Memory: new(int32(4)), }, }, }, @@ -1018,16 +1017,16 @@ func TestLoadFlavorId(t *testing.T) { &mongodbflex.ListFlavorsResponse{ Flavors: []mongodbflex.InstanceFlavor{ { - Id: utils.Ptr("fid-1"), - Cpu: utils.Ptr(int32(1)), - Description: utils.Ptr("description"), - Memory: utils.Ptr(int32(8)), + Id: new("fid-1"), + Cpu: new(int32(1)), + Description: new("description"), + Memory: new(int32(8)), }, { - Id: utils.Ptr("fid-2"), - Cpu: utils.Ptr(int32(1)), - Description: utils.Ptr("description"), - Memory: utils.Ptr(int32(4)), + Id: new("fid-2"), + Cpu: new(int32(1)), + Description: new("description"), + Memory: new(int32(4)), }, }, }, diff --git a/stackit/internal/services/mongodbflex/mongodbflex_test.go b/stackit/internal/services/mongodbflex/mongodbflex_test.go index a27ed34c4..8b55af298 100644 --- a/stackit/internal/services/mongodbflex/mongodbflex_test.go +++ b/stackit/internal/services/mongodbflex/mongodbflex_test.go @@ -8,7 +8,6 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/stackitcloud/stackit-sdk-go/core/utils" mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -65,16 +64,16 @@ resource "stackit_mongodbflex_instance" "instance" { Description: "ListFlavors", ToJsonBody: &mongodbflex.ListFlavorsResponse{Flavors: []mongodbflex.InstanceFlavor{ { - Description: utils.Ptr("flava-flav"), - Cpu: utils.Ptr(int32(2)), - Id: utils.Ptr("flavor-id"), - Memory: utils.Ptr(int32(4)), + Description: new("flava-flav"), + Cpu: new(int32(2)), + Id: new("flavor-id"), + Memory: new(int32(4)), }, }}, }, testutil.MockResponse{ Description: "create instance", - ToJsonBody: &mongodbflex.CreateInstanceResponse{Id: utils.Ptr(instanceId)}, + ToJsonBody: &mongodbflex.CreateInstanceResponse{Id: new(instanceId)}, }, testutil.MockResponse{Description: "create waiter", StatusCode: http.StatusInternalServerError}, ) @@ -136,7 +135,7 @@ resource "stackit_mongodbflex_user" "user" { s.Reset( testutil.MockResponse{ Description: "create user", - ToJsonBody: &mongodbflex.CreateUserResponse{Item: &mongodbflex.User{Id: utils.Ptr(userId)}}, + ToJsonBody: &mongodbflex.CreateUserResponse{Item: &mongodbflex.User{Id: new(userId)}}, }, testutil.MockResponse{Description: "failing waiter", StatusCode: http.StatusInternalServerError}, ) diff --git a/stackit/internal/services/mongodbflex/user/datasource_test.go b/stackit/internal/services/mongodbflex/user/datasource_test.go index 61bd342b5..02507bcdf 100644 --- a/stackit/internal/services/mongodbflex/user/datasource_test.go +++ b/stackit/internal/services/mongodbflex/user/datasource_test.go @@ -7,7 +7,6 @@ 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/core/utils" mongodbflex "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex/v2api" ) @@ -47,10 +46,10 @@ func TestMapDataSourceFields(t *testing.T) { "role_2", "", }, - Username: utils.Ptr("username"), - Database: utils.Ptr("database"), - Host: utils.Ptr("host"), - Port: utils.Ptr(int64(1234)), + Username: new("username"), + Database: new("database"), + Host: new("host"), + Port: new(int64(1234)), }, }, testRegion, @@ -75,12 +74,12 @@ func TestMapDataSourceFields(t *testing.T) { "null_fields_and_int_conversions", &mongodbflex.GetUserResponse{ Item: &mongodbflex.InstanceResponseUser{ - Id: utils.Ptr(userId), + Id: new(userId), Roles: []string{}, Username: nil, Database: nil, Host: nil, - Port: utils.Ptr(int64(2123456789)), + Port: new(int64(2123456789)), }, }, testRegion, diff --git a/stackit/internal/services/mongodbflex/user/resource_test.go b/stackit/internal/services/mongodbflex/user/resource_test.go index 3df36b909..d3f8dab50 100644 --- a/stackit/internal/services/mongodbflex/user/resource_test.go +++ b/stackit/internal/services/mongodbflex/user/resource_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/google/uuid" - "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/attr" @@ -35,8 +34,8 @@ func TestMapFieldsCreate(t *testing.T) { "default_values", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: utils.Ptr(userId), - Password: utils.Ptr(""), + Id: new(userId), + Password: new(""), }, }, testRegion, @@ -60,18 +59,18 @@ func TestMapFieldsCreate(t *testing.T) { "simple_values", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: utils.Ptr(userId), + Id: new(userId), Roles: []string{ "role_1", "role_2", "", }, - Username: utils.Ptr("username"), - Database: utils.Ptr("database"), - Password: utils.Ptr("password"), - Host: utils.Ptr("host"), - Port: utils.Ptr(int64(1234)), - Uri: utils.Ptr("uri"), + Username: new("username"), + Database: new("database"), + Password: new("password"), + Host: new("host"), + Port: new(int64(1234)), + Uri: new("uri"), }, }, testRegion, @@ -99,13 +98,13 @@ func TestMapFieldsCreate(t *testing.T) { "null_fields_and_int_conversions", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: utils.Ptr(userId), + Id: new(userId), Roles: []string{}, Username: nil, Database: nil, - Password: utils.Ptr(""), + Password: new(""), Host: nil, - Port: utils.Ptr(int64(2123456789)), + Port: new(int64(2123456789)), Uri: nil, }, }, @@ -153,7 +152,7 @@ func TestMapFieldsCreate(t *testing.T) { "no_password", &mongodbflex.CreateUserResponse{ Item: &mongodbflex.User{ - Id: utils.Ptr(userId), + Id: new(userId), }, }, testRegion, @@ -221,10 +220,10 @@ func TestMapFields(t *testing.T) { "role_2", "", }, - Username: utils.Ptr("username"), - Database: utils.Ptr("database"), - Host: utils.Ptr("host"), - Port: utils.Ptr(int64(1234)), + Username: new("username"), + Database: new("database"), + Host: new("host"), + Port: new(int64(1234)), }, }, testRegion, @@ -250,12 +249,12 @@ func TestMapFields(t *testing.T) { "null_fields_and_int_conversions", &mongodbflex.GetUserResponse{ Item: &mongodbflex.InstanceResponseUser{ - Id: utils.Ptr(userId), + Id: new(userId), Roles: []string{}, Username: nil, Database: nil, Host: nil, - Port: utils.Ptr(int64(2123456789)), + Port: new(int64(2123456789)), }, }, testRegion, @@ -355,7 +354,7 @@ func TestToCreatePayload(t *testing.T) { "role_1", "role_2", }, - Username: utils.Ptr("username"), + Username: new("username"), Database: "database", }, true,