diff --git a/go.mod b/go.mod index c512153c2..70f1e0cc2 100644 --- a/go.mod +++ b/go.mod @@ -35,8 +35,10 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/redis v0.28.1 github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0 github.com/stackitcloud/stackit-sdk-go/services/scf v0.7.0 + github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.14.3 + github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.6.0 github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.17.0 - github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 + github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.6.0 github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.0 github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.4.1 diff --git a/go.sum b/go.sum index 00b95d6e7..50f59bebc 100644 --- a/go.sum +++ b/go.sum @@ -724,6 +724,8 @@ github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.17.0 h1:6gDKTx github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.17.0/go.mod h1:vSWUMTsMbtniEo1I+eCsjCOTODR4iproNAeqG3vr/4I= github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 h1:LLyANBzE8sQa0/49tQBqq4sVLhNgwdqCeQm76srJHWw= github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8/go.mod h1:/bmg57XZu+bGczzcoumrukiGMPGzI2mOyTT4BVIQUBs= +github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.6.0 h1:OGAaEbuoxTZnsWbtFmhkvdvCCV/RpYuE3ALQXmRyOOc= +github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.6.0/go.mod h1:h2fhcXRiSFP9yJXY8eb37e+2PhMW11g1GB8LL/EQ1aU= github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.0 h1:4MYNb3VQjVnVPfJ9xhDbSQgoSkxQZJ0tsv9N7O43/RI= github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.0/go.mod h1:iVCh5xZW/DHBMnJW4Zrw8KMhQIBRAETcnTPi5bbcQIE= github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 h1:l1EDIlXce2C8JcbBDHVa6nZ4SjPTqmnALTgrhms+NKI= diff --git a/stackit/internal/services/serverbackup/enable/datasource.go b/stackit/internal/services/serverbackup/enable/datasource.go index 039ecde9d..b892208ce 100644 --- a/stackit/internal/services/serverbackup/enable/datasource.go +++ b/stackit/internal/services/serverbackup/enable/datasource.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" @@ -130,7 +130,7 @@ func (d *serverBackupEnableDataSource) Read(ctx context.Context, req datasource. ctx = tflog.SetField(ctx, "server_id", serverId) ctx = tflog.SetField(ctx, "region", region) - serviceResp, err := d.client.GetServiceResource(ctx, projectId, serverId, region).Execute() + serviceResp, err := d.client.DefaultAPI.GetServiceResource(ctx, projectId, serverId, region).Execute() if err != nil { utils.LogError( ctx, diff --git a/stackit/internal/services/serverbackup/enable/datasource_test.go b/stackit/internal/services/serverbackup/enable/datasource_test.go index 0709a1cc8..86c8c2bda 100644 --- a/stackit/internal/services/serverbackup/enable/datasource_test.go +++ b/stackit/internal/services/serverbackup/enable/datasource_test.go @@ -6,7 +6,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" ) func TestDataMapFields(t *testing.T) { diff --git a/stackit/internal/services/serverbackup/enable/resource.go b/stackit/internal/services/serverbackup/enable/resource.go index 19cea5715..aaadfe3bc 100644 --- a/stackit/internal/services/serverbackup/enable/resource.go +++ b/stackit/internal/services/serverbackup/enable/resource.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" @@ -189,7 +189,7 @@ func (r *serverBackupEnableResource) Create(ctx context.Context, req resource.Cr ctx = tflog.SetField(ctx, "server_id", serverId) ctx = tflog.SetField(ctx, "region", region) - err := r.client.EnableServiceResource(ctx, projectId, serverId, region).EnableServiceResourcePayload(serverbackup.EnableServiceResourcePayload{}).Execute() + err := r.client.DefaultAPI.EnableServiceResource(ctx, projectId, serverId, region).EnableServiceResourcePayload(serverbackup.EnableServiceResourcePayload{}).Execute() if err != nil { var oapiErr *oapierror.GenericOpenAPIError ok := errors.As(err, &oapiErr) @@ -201,7 +201,7 @@ func (r *serverBackupEnableResource) Create(ctx context.Context, req resource.Cr tflog.Info(ctx, "Server backup is already enabled for this server. Please check duplicate resources.") } - serviceResp, err := r.client.GetServiceResource(ctx, projectId, serverId, region).Execute() + serviceResp, err := r.client.DefaultAPI.GetServiceResource(ctx, projectId, serverId, region).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading server backup enable", fmt.Sprintf("Calling API: %v", err)) return @@ -243,7 +243,7 @@ func (r *serverBackupEnableResource) Read(ctx context.Context, req resource.Read ctx = tflog.SetField(ctx, "server_id", serverId) ctx = tflog.SetField(ctx, "region", region) - serviceResp, err := r.client.GetServiceResource(ctx, projectId, serverId, region).Execute() + serviceResp, err := r.client.DefaultAPI.GetServiceResource(ctx, projectId, serverId, 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 { @@ -297,7 +297,7 @@ func (r *serverBackupEnableResource) Delete(ctx context.Context, req resource.De ctx = tflog.SetField(ctx, "server_id", serverId) ctx = tflog.SetField(ctx, "region", region) - err := r.client.DisableServiceResource(ctx, projectId, serverId, region).Execute() + err := r.client.DefaultAPI.DisableServiceResource(ctx, projectId, serverId, region).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting server backup enable", fmt.Sprintf("Calling API: %v", err)) return diff --git a/stackit/internal/services/serverbackup/enable/resource_test.go b/stackit/internal/services/serverbackup/enable/resource_test.go index decbaee44..c91e1d4bd 100644 --- a/stackit/internal/services/serverbackup/enable/resource_test.go +++ b/stackit/internal/services/serverbackup/enable/resource_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" ) func TestMapFields(t *testing.T) { diff --git a/stackit/internal/services/serverbackup/schedule/resource.go b/stackit/internal/services/serverbackup/schedule/resource.go index 0d497a94a..6c085cfbd 100644 --- a/stackit/internal/services/serverbackup/schedule/resource.go +++ b/stackit/internal/services/serverbackup/schedule/resource.go @@ -7,17 +7,17 @@ import ( "strconv" "strings" + "github.com/hashicorp/terraform-plugin-framework-validators/int32validator" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier" serverbackupUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serverbackup/utils" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "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/schema/validator" @@ -30,7 +30,7 @@ import ( "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -45,7 +45,7 @@ type Model struct { ID types.String `tfsdk:"id"` ProjectId types.String `tfsdk:"project_id"` ServerId types.String `tfsdk:"server_id"` - BackupScheduleId types.Int64 `tfsdk:"backup_schedule_id"` + BackupScheduleId types.Int32 `tfsdk:"backup_schedule_id"` Name types.String `tfsdk:"name"` Rrule types.String `tfsdk:"rrule"` Enabled types.Bool `tfsdk:"enabled"` @@ -56,7 +56,7 @@ type Model struct { // scheduleBackupPropertiesModel maps schedule backup_properties data type scheduleBackupPropertiesModel struct { BackupName types.String `tfsdk:"name"` - RetentionPeriod types.Int64 `tfsdk:"retention_period"` + RetentionPeriod types.Int32 `tfsdk:"retention_period"` VolumeIds types.List `tfsdk:"volume_ids"` } @@ -145,14 +145,14 @@ func (r *scheduleResource) Schema(_ context.Context, _ resource.SchemaRequest, r stringvalidator.LengthBetween(1, 255), }, }, - "backup_schedule_id": schema.Int64Attribute{ + "backup_schedule_id": schema.Int32Attribute{ Description: "Backup schedule ID.", Computed: true, - PlanModifiers: []planmodifier.Int64{ - int64planmodifier.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int32{ + int32planmodifier.UseStateForUnknown(), }, - Validators: []validator.Int64{ - int64validator.AtLeast(1), + Validators: []validator.Int32{ + int32validator.AtLeast(1), }, }, "project_id": schema.StringAttribute{ @@ -209,10 +209,10 @@ func (r *scheduleResource) Schema(_ context.Context, _ resource.SchemaRequest, r "name": schema.StringAttribute{ Required: true, }, - "retention_period": schema.Int64Attribute{ + "retention_period": schema.Int32Attribute{ Required: true, - Validators: []validator.Int64{ - int64validator.AtLeast(1), + Validators: []validator.Int32{ + int32validator.AtLeast(1), }, }, }, @@ -268,7 +268,7 @@ func (r *scheduleResource) Create(ctx context.Context, req resource.CreateReques core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating server backup schedule", fmt.Sprintf("Creating API payload: %v", err)) return } - scheduleResp, err := r.client.CreateBackupSchedule(ctx, projectId, serverId, region).CreateBackupSchedulePayload(*payload).Execute() + scheduleResp, err := r.client.DefaultAPI.CreateBackupSchedule(ctx, projectId, serverId, region).CreateBackupSchedulePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating server backup schedule", fmt.Sprintf("Calling API: %v", err)) return @@ -276,7 +276,7 @@ func (r *scheduleResource) Create(ctx context.Context, req resource.CreateReques ctx = core.LogResponse(ctx) - ctx = tflog.SetField(ctx, "backup_schedule_id", *scheduleResp.Id) + ctx = tflog.SetField(ctx, "backup_schedule_id", scheduleResp.Id) // Map response body to schema err = mapFields(ctx, scheduleResp, &model, region) @@ -305,7 +305,7 @@ func (r *scheduleResource) Read(ctx context.Context, req resource.ReadRequest, r projectId := model.ProjectId.ValueString() serverId := model.ServerId.ValueString() - backupScheduleId := model.BackupScheduleId.ValueInt64() + backupScheduleId := model.BackupScheduleId.ValueInt32() region := r.providerData.GetRegionWithOverride(model.Region) ctx = tflog.SetField(ctx, "project_id", projectId) @@ -313,7 +313,7 @@ func (r *scheduleResource) Read(ctx context.Context, req resource.ReadRequest, r ctx = tflog.SetField(ctx, "backup_schedule_id", backupScheduleId) ctx = tflog.SetField(ctx, "region", region) - scheduleResp, err := r.client.GetBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(backupScheduleId, 10)).Execute() + scheduleResp, err := r.client.DefaultAPI.GetBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(int64(backupScheduleId), 10)).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 { @@ -355,7 +355,7 @@ func (r *scheduleResource) Update(ctx context.Context, req resource.UpdateReques projectId := model.ProjectId.ValueString() serverId := model.ServerId.ValueString() - backupScheduleId := model.BackupScheduleId.ValueInt64() + backupScheduleId := model.BackupScheduleId.ValueInt32() region := r.providerData.GetRegionWithOverride(model.Region) ctx = tflog.SetField(ctx, "project_id", projectId) @@ -370,7 +370,7 @@ func (r *scheduleResource) Update(ctx context.Context, req resource.UpdateReques return } - scheduleResp, err := r.client.UpdateBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(backupScheduleId, 10)).UpdateBackupSchedulePayload(*payload).Execute() + scheduleResp, err := r.client.DefaultAPI.UpdateBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(int64(backupScheduleId), 10)).UpdateBackupSchedulePayload(*payload).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating server backup schedule", fmt.Sprintf("Calling API: %v", err)) return @@ -405,7 +405,7 @@ func (r *scheduleResource) Delete(ctx context.Context, req resource.DeleteReques projectId := model.ProjectId.ValueString() serverId := model.ServerId.ValueString() - backupScheduleId := model.BackupScheduleId.ValueInt64() + backupScheduleId := model.BackupScheduleId.ValueInt32() region := r.providerData.GetRegionWithOverride(model.Region) ctx = tflog.SetField(ctx, "project_id", projectId) @@ -413,7 +413,7 @@ func (r *scheduleResource) Delete(ctx context.Context, req resource.DeleteReques ctx = tflog.SetField(ctx, "backup_schedule_id", backupScheduleId) ctx = tflog.SetField(ctx, "region", region) - err := r.client.DeleteBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(backupScheduleId, 10)).Execute() + err := r.client.DefaultAPI.DeleteBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(int64(backupScheduleId), 10)).Execute() if err != nil { core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting server backup schedule", fmt.Sprintf("Calling API: %v", err)) return @@ -466,18 +466,15 @@ func mapFields(ctx context.Context, schedule *serverbackup.BackupSchedule, model if model == nil { return fmt.Errorf("model input is nil") } - if schedule.Id == nil { - return fmt.Errorf("response id is nil") - } - model.BackupScheduleId = types.Int64PointerValue(schedule.Id) + model.BackupScheduleId = types.Int32Value(schedule.Id) model.ID = utils.BuildInternalTerraformId( model.ProjectId.ValueString(), region, model.ServerId.ValueString(), - strconv.FormatInt(model.BackupScheduleId.ValueInt64(), 10), + strconv.FormatInt(int64(model.BackupScheduleId.ValueInt32()), 10), ) - model.Name = types.StringPointerValue(schedule.Name) - model.Rrule = types.StringPointerValue(schedule.Rrule) - model.Enabled = types.BoolPointerValue(schedule.Enabled) + model.Name = types.StringValue(schedule.Name) + model.Rrule = types.StringValue(schedule.Rrule) + model.Enabled = types.BoolValue(schedule.Enabled) if schedule.BackupProperties == nil { model.BackupProperties = nil return nil @@ -494,7 +491,7 @@ func mapFields(ctx context.Context, schedule *serverbackup.BackupSchedule, model } } - respVolIds := *schedule.BackupProperties.VolumeIds + respVolIds := schedule.BackupProperties.VolumeIds reconciledVolIds := utils.ReconcileStringSlices(modelVolIds, respVolIds) var diags diag.Diagnostics @@ -504,8 +501,8 @@ func mapFields(ctx context.Context, schedule *serverbackup.BackupSchedule, model } } model.BackupProperties = &scheduleBackupPropertiesModel{ - BackupName: types.StringValue(*schedule.BackupProperties.Name), - RetentionPeriod: types.Int64Value(*schedule.BackupProperties.RetentionPeriod), + BackupName: types.StringValue(schedule.BackupProperties.Name), + RetentionPeriod: types.Int32Value(schedule.BackupProperties.RetentionPeriod), VolumeIds: volIds, } model.Region = types.StringValue(region) @@ -521,7 +518,7 @@ func (r *scheduleResource) enableBackupsService(ctx context.Context, model *Mode region := r.providerData.GetRegionWithOverride(model.Region) tflog.Debug(ctx, "Enabling server backup service") - request := r.client.EnableServiceResource(ctx, projectId, serverId, region). + request := r.client.DefaultAPI.EnableServiceResource(ctx, projectId, serverId, region). EnableServiceResourcePayload(serverbackup.EnableServiceResourcePayload{}) if err := request.Execute(); err != nil { @@ -546,16 +543,16 @@ func (r *scheduleResource) disableBackupsService(ctx context.Context, model *Mod region := r.providerData.GetRegionWithOverride(model.Region) tflog.Debug(ctx, "Checking for existing backups") - backups, err := r.client.ListBackups(ctx, projectId, serverId, region).Execute() + backups, err := r.client.DefaultAPI.ListBackups(ctx, projectId, serverId, region).Execute() if err != nil { return fmt.Errorf("list backups: %w", err) } - if len(*backups.Items) > 0 { + if len(backups.Items) > 0 { tflog.Debug(ctx, "Backups found - will not disable server backup service") return nil } - err = r.client.DisableServiceResourceExecute(ctx, projectId, serverId, region) + err = r.client.DefaultAPI.DisableServiceResource(ctx, projectId, serverId, region).Execute() if err != nil { return fmt.Errorf("disable server backup service: %w", err) } @@ -583,15 +580,15 @@ func toCreatePayload(model *Model) (*serverbackup.CreateBackupSchedulePayload, e ids = nil } backupProperties = serverbackup.BackupProperties{ - Name: conversion.StringValueToPointer(model.BackupProperties.BackupName), - RetentionPeriod: conversion.Int64ValueToPointer(model.BackupProperties.RetentionPeriod), - VolumeIds: &ids, + Name: model.BackupProperties.BackupName.ValueString(), + RetentionPeriod: model.BackupProperties.RetentionPeriod.ValueInt32(), + VolumeIds: ids, } } return &serverbackup.CreateBackupSchedulePayload{ - Enabled: conversion.BoolValueToPointer(model.Enabled), - Name: conversion.StringValueToPointer(model.Name), - Rrule: conversion.StringValueToPointer(model.Rrule), + Enabled: model.Enabled.ValueBool(), + Name: model.Name.ValueString(), + Rrule: model.Rrule.ValueString(), BackupProperties: &backupProperties, }, nil } @@ -616,16 +613,16 @@ func toUpdatePayload(model *Model) (*serverbackup.UpdateBackupSchedulePayload, e ids = nil } backupProperties = serverbackup.BackupProperties{ - Name: conversion.StringValueToPointer(model.BackupProperties.BackupName), - RetentionPeriod: conversion.Int64ValueToPointer(model.BackupProperties.RetentionPeriod), - VolumeIds: &ids, + Name: model.BackupProperties.BackupName.ValueString(), + RetentionPeriod: model.BackupProperties.RetentionPeriod.ValueInt32(), + VolumeIds: ids, } } return &serverbackup.UpdateBackupSchedulePayload{ - Enabled: conversion.BoolValueToPointer(model.Enabled), - Name: conversion.StringValueToPointer(model.Name), - Rrule: conversion.StringValueToPointer(model.Rrule), + Enabled: model.Enabled.ValueBool(), + Name: model.Name.ValueString(), + Rrule: model.Rrule.ValueString(), BackupProperties: &backupProperties, }, nil } diff --git a/stackit/internal/services/serverbackup/schedule/resource_test.go b/stackit/internal/services/serverbackup/schedule/resource_test.go index f40cea6f9..967e11b18 100644 --- a/stackit/internal/services/serverbackup/schedule/resource_test.go +++ b/stackit/internal/services/serverbackup/schedule/resource_test.go @@ -6,53 +6,56 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" - sdk "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" ) func TestMapFields(t *testing.T) { tests := []struct { description string - input *sdk.BackupSchedule + input *serverbackup.BackupSchedule expected Model isValid bool }{ { "default_values", - &sdk.BackupSchedule{ - Id: new(int64(5)), + &serverbackup.BackupSchedule{ + Id: int32(5), }, Model{ ID: types.StringValue("project_uid,eu01,server_uid,5"), ProjectId: types.StringValue("project_uid"), ServerId: types.StringValue("server_uid"), - BackupScheduleId: types.Int64Value(5), + BackupScheduleId: types.Int32Value(5), + Name: types.StringValue(""), + Rrule: types.StringValue(""), + Enabled: types.BoolValue(false), }, true, }, { "simple_values", - &sdk.BackupSchedule{ - Id: new(int64(5)), - Enabled: new(true), - Name: new("backup_schedule_name_1"), - Rrule: new("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), - BackupProperties: &sdk.BackupProperties{ - Name: new("backup_name_1"), - RetentionPeriod: new(int64(3)), - VolumeIds: &[]string{"uuid1", "uuid2"}, + &serverbackup.BackupSchedule{ + Id: int32(5), + Enabled: true, + Name: "backup_schedule_name_1", + Rrule: "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1", + BackupProperties: &serverbackup.BackupProperties{ + Name: "backup_name_1", + RetentionPeriod: int32(3), + VolumeIds: []string{"uuid1", "uuid2"}, }, }, Model{ ServerId: types.StringValue("server_uid"), ProjectId: types.StringValue("project_uid"), - BackupScheduleId: types.Int64Value(5), + BackupScheduleId: types.Int32Value(5), ID: types.StringValue("project_uid,eu01,server_uid,5"), Name: types.StringValue("backup_schedule_name_1"), Rrule: types.StringValue("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), Enabled: types.BoolValue(true), BackupProperties: &scheduleBackupPropertiesModel{ BackupName: types.StringValue("backup_name_1"), - RetentionPeriod: types.Int64Value(3), + RetentionPeriod: types.Int32Value(3), VolumeIds: listValueFrom([]string{"uuid1", "uuid2"}), }, Region: types.StringValue("eu01"), @@ -65,12 +68,6 @@ func TestMapFields(t *testing.T) { Model{}, false, }, - { - "no_resource_id", - &sdk.BackupSchedule{}, - Model{}, - false, - }, } for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { @@ -100,14 +97,14 @@ func TestToCreatePayload(t *testing.T) { tests := []struct { description string input *Model - expected *sdk.CreateBackupSchedulePayload + expected *serverbackup.CreateBackupSchedulePayload isValid bool }{ { "default_values", &Model{}, - &sdk.CreateBackupSchedulePayload{ - BackupProperties: &sdk.BackupProperties{}, + &serverbackup.CreateBackupSchedulePayload{ + BackupProperties: &serverbackup.BackupProperties{}, }, true, }, @@ -119,11 +116,11 @@ func TestToCreatePayload(t *testing.T) { Rrule: types.StringValue("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), BackupProperties: nil, }, - &sdk.CreateBackupSchedulePayload{ - Name: new("name"), - Enabled: new(true), - Rrule: new("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), - BackupProperties: &sdk.BackupProperties{}, + &serverbackup.CreateBackupSchedulePayload{ + Name: "name", + Enabled: true, + Rrule: "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1", + BackupProperties: &serverbackup.BackupProperties{}, }, true, }, @@ -133,10 +130,10 @@ func TestToCreatePayload(t *testing.T) { Name: types.StringValue(""), Rrule: types.StringValue(""), }, - &sdk.CreateBackupSchedulePayload{ - BackupProperties: &sdk.BackupProperties{}, - Name: new(""), - Rrule: new(""), + &serverbackup.CreateBackupSchedulePayload{ + BackupProperties: &serverbackup.BackupProperties{}, + Name: "", + Rrule: "", }, true, }, @@ -170,14 +167,14 @@ func TestToUpdatePayload(t *testing.T) { tests := []struct { description string input *Model - expected *sdk.UpdateBackupSchedulePayload + expected *serverbackup.UpdateBackupSchedulePayload isValid bool }{ { "default_values", &Model{}, - &sdk.UpdateBackupSchedulePayload{ - BackupProperties: &sdk.BackupProperties{}, + &serverbackup.UpdateBackupSchedulePayload{ + BackupProperties: &serverbackup.BackupProperties{}, }, true, }, @@ -189,11 +186,11 @@ func TestToUpdatePayload(t *testing.T) { Rrule: types.StringValue("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), BackupProperties: nil, }, - &sdk.UpdateBackupSchedulePayload{ - Name: new("name"), - Enabled: new(true), - Rrule: new("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), - BackupProperties: &sdk.BackupProperties{}, + &serverbackup.UpdateBackupSchedulePayload{ + Name: "name", + Enabled: true, + Rrule: "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1", + BackupProperties: &serverbackup.BackupProperties{}, }, true, }, @@ -203,10 +200,10 @@ func TestToUpdatePayload(t *testing.T) { Name: types.StringValue(""), Rrule: types.StringValue(""), }, - &sdk.UpdateBackupSchedulePayload{ - BackupProperties: &sdk.BackupProperties{}, - Name: new(""), - Rrule: new(""), + &serverbackup.UpdateBackupSchedulePayload{ + BackupProperties: &serverbackup.BackupProperties{}, + Name: "", + Rrule: "", }, true, }, diff --git a/stackit/internal/services/serverbackup/schedule/schedule_datasource.go b/stackit/internal/services/serverbackup/schedule/schedule_datasource.go index 1905f15c1..31874bdef 100644 --- a/stackit/internal/services/serverbackup/schedule/schedule_datasource.go +++ b/stackit/internal/services/serverbackup/schedule/schedule_datasource.go @@ -19,7 +19,7 @@ import ( "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -72,7 +72,7 @@ func (r *scheduleDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: "The schedule name.", Computed: true, }, - "backup_schedule_id": schema.Int64Attribute{ + "backup_schedule_id": schema.Int32Attribute{ Description: "Backup schedule ID.", Required: true, }, @@ -111,7 +111,7 @@ func (r *scheduleDataSource) Schema(_ context.Context, _ datasource.SchemaReques "name": schema.StringAttribute{ Computed: true, }, - "retention_period": schema.Int64Attribute{ + "retention_period": schema.Int32Attribute{ Computed: true, }, }, @@ -138,7 +138,7 @@ func (r *scheduleDataSource) Read(ctx context.Context, req datasource.ReadReques projectId := model.ProjectId.ValueString() serverId := model.ServerId.ValueString() - backupScheduleId := model.BackupScheduleId.ValueInt64() + backupScheduleId := model.BackupScheduleId.ValueInt32() region := r.providerData.GetRegionWithOverride(model.Region) ctx = tflog.SetField(ctx, "project_id", projectId) @@ -146,14 +146,14 @@ func (r *scheduleDataSource) Read(ctx context.Context, req datasource.ReadReques ctx = tflog.SetField(ctx, "backup_schedule_id", backupScheduleId) ctx = tflog.SetField(ctx, "region", region) - scheduleResp, err := r.client.GetBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(backupScheduleId, 10)).Execute() + scheduleResp, err := r.client.DefaultAPI.GetBackupSchedule(ctx, projectId, serverId, region, strconv.FormatInt(int64(backupScheduleId), 10)).Execute() if err != nil { utils.LogError( ctx, &resp.Diagnostics, err, "Reading server backup schedule", - fmt.Sprintf("Backup schedule with ID %q or server with ID %q does not exist in project %q.", strconv.FormatInt(backupScheduleId, 10), serverId, projectId), + fmt.Sprintf("Backup schedule with ID %q or server with ID %q does not exist in project %q.", strconv.FormatInt(int64(backupScheduleId), 10), serverId, projectId), map[int]string{ http.StatusForbidden: fmt.Sprintf("Project with ID %q not found or forbidden access", projectId), }, diff --git a/stackit/internal/services/serverbackup/schedule/schedules_datasource.go b/stackit/internal/services/serverbackup/schedule/schedules_datasource.go index 005a98bd8..b7655d32c 100644 --- a/stackit/internal/services/serverbackup/schedule/schedules_datasource.go +++ b/stackit/internal/services/serverbackup/schedule/schedules_datasource.go @@ -18,7 +18,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/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" ) // Ensure the implementation satisfies the expected interfaces. @@ -88,7 +88,7 @@ func (r *schedulesDataSource) Schema(_ context.Context, _ datasource.SchemaReque Computed: true, NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ - "backup_schedule_id": schema.Int64Attribute{ + "backup_schedule_id": schema.Int32Attribute{ Computed: true, }, "name": schema.StringAttribute{ @@ -114,7 +114,7 @@ func (r *schedulesDataSource) Schema(_ context.Context, _ datasource.SchemaReque "name": schema.StringAttribute{ Computed: true, }, - "retention_period": schema.Int64Attribute{ + "retention_period": schema.Int32Attribute{ Computed: true, }, }, @@ -142,7 +142,7 @@ type schedulesDataSourceModel struct { // schedulesDatasourceItemModel maps schedule schema data. type schedulesDatasourceItemModel struct { - BackupScheduleId types.Int64 `tfsdk:"backup_schedule_id"` + BackupScheduleId types.Int32 `tfsdk:"backup_schedule_id"` Name types.String `tfsdk:"name"` Rrule types.String `tfsdk:"rrule"` Enabled types.Bool `tfsdk:"enabled"` @@ -167,7 +167,7 @@ func (r *schedulesDataSource) Read(ctx context.Context, req datasource.ReadReque ctx = tflog.SetField(ctx, "server_id", serverId) ctx = tflog.SetField(ctx, "region", region) - schedules, err := r.client.ListBackupSchedules(ctx, projectId, serverId, region).Execute() + schedules, err := r.client.DefaultAPI.ListBackupSchedules(ctx, projectId, serverId, region).Execute() if err != nil { utils.LogError( ctx, @@ -216,20 +216,20 @@ func mapSchedulesDatasourceFields(ctx context.Context, schedules *serverbackup.G model.ID = utils.BuildInternalTerraformId(projectId, region, serverId) model.Region = types.StringValue(region) - for _, schedule := range *schedules.Items { + for _, schedule := range schedules.Items { scheduleState := schedulesDatasourceItemModel{ - BackupScheduleId: types.Int64Value(*schedule.Id), - Name: types.StringValue(*schedule.Name), - Rrule: types.StringValue(*schedule.Rrule), - Enabled: types.BoolValue(*schedule.Enabled), + BackupScheduleId: types.Int32Value(schedule.Id), + Name: types.StringValue(schedule.Name), + Rrule: types.StringValue(schedule.Rrule), + Enabled: types.BoolValue(schedule.Enabled), } ids, diags := types.ListValueFrom(ctx, types.StringType, schedule.BackupProperties.VolumeIds) if diags.HasError() { return fmt.Errorf("failed to map hosts: %w", core.DiagsToError(diags)) } scheduleState.BackupProperties = &scheduleBackupPropertiesModel{ - BackupName: types.StringValue(*schedule.BackupProperties.Name), - RetentionPeriod: types.Int64Value(*schedule.BackupProperties.RetentionPeriod), + BackupName: types.StringValue(schedule.BackupProperties.Name), + RetentionPeriod: types.Int32Value(schedule.BackupProperties.RetentionPeriod), VolumeIds: ids, } model.Items = append(model.Items, scheduleState) diff --git a/stackit/internal/services/serverbackup/schedule/schedules_datasource_test.go b/stackit/internal/services/serverbackup/schedule/schedules_datasource_test.go index 9e2ae0203..048121052 100644 --- a/stackit/internal/services/serverbackup/schedule/schedules_datasource_test.go +++ b/stackit/internal/services/serverbackup/schedule/schedules_datasource_test.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - sdk "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" ) func listValueFrom(items []string) basetypes.ListValue { @@ -18,14 +18,14 @@ func listValueFrom(items []string) basetypes.ListValue { func TestMapSchedulesDataSourceFields(t *testing.T) { tests := []struct { description string - input *sdk.GetBackupSchedulesResponse + input *serverbackup.GetBackupSchedulesResponse expected schedulesDataSourceModel isValid bool }{ { "empty response", - &sdk.GetBackupSchedulesResponse{ - Items: &[]sdk.BackupSchedule{}, + &serverbackup.GetBackupSchedulesResponse{ + Items: []serverbackup.BackupSchedule{}, }, schedulesDataSourceModel{ ID: types.StringValue("project_uid,eu01,server_uid"), @@ -38,17 +38,17 @@ func TestMapSchedulesDataSourceFields(t *testing.T) { }, { "simple_values", - &sdk.GetBackupSchedulesResponse{ - Items: &[]sdk.BackupSchedule{ + &serverbackup.GetBackupSchedulesResponse{ + Items: []serverbackup.BackupSchedule{ { - Id: new(int64(5)), - Enabled: new(true), - Name: new("backup_schedule_name_1"), - Rrule: new("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), - BackupProperties: &sdk.BackupProperties{ - Name: new("backup_name_1"), - RetentionPeriod: new(int64(14)), - VolumeIds: &[]string{"uuid1", "uuid2"}, + Id: int32(5), + Enabled: true, + Name: "backup_schedule_name_1", + Rrule: "DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1", + BackupProperties: &serverbackup.BackupProperties{ + Name: "backup_name_1", + RetentionPeriod: int32(14), + VolumeIds: []string{"uuid1", "uuid2"}, }, }, }, @@ -59,13 +59,13 @@ func TestMapSchedulesDataSourceFields(t *testing.T) { ProjectId: types.StringValue("project_uid"), Items: []schedulesDatasourceItemModel{ { - BackupScheduleId: types.Int64Value(5), + BackupScheduleId: types.Int32Value(5), Name: types.StringValue("backup_schedule_name_1"), Rrule: types.StringValue("DTSTART;TZID=Europe/Sofia:20200803T023000 RRULE:FREQ=DAILY;INTERVAL=1"), Enabled: types.BoolValue(true), BackupProperties: &scheduleBackupPropertiesModel{ BackupName: types.StringValue("backup_name_1"), - RetentionPeriod: types.Int64Value(14), + RetentionPeriod: types.Int32Value(14), VolumeIds: listValueFrom([]string{"uuid1", "uuid2"}), }, }, diff --git a/stackit/internal/services/serverbackup/serverbackup_acc_test.go b/stackit/internal/services/serverbackup/serverbackup_acc_test.go index b906cf854..59589f93e 100644 --- a/stackit/internal/services/serverbackup/serverbackup_acc_test.go +++ b/stackit/internal/services/serverbackup/serverbackup_acc_test.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" @@ -333,7 +333,7 @@ func testAccCheckServerBackupScheduleDestroy(s *terraform.State) error { schedulesToDestroy = append(schedulesToDestroy, scheduleId) } - schedulesResp, err := client.ListBackupSchedules(ctx, testutil.ProjectId, serverId, testutil.Region).Execute() + schedulesResp, err := client.DefaultAPI.ListBackupSchedules(ctx, testutil.ProjectId, serverId, testutil.Region).Execute() // The destroy functions are called after all resources are cleaned up. // If the server was successfully destroyed we should see a 404 here. if err != nil { @@ -343,14 +343,14 @@ func testAccCheckServerBackupScheduleDestroy(s *terraform.State) error { return fmt.Errorf("getting schedulesResp: %w", err) } - schedules := *schedulesResp.Items + schedules := schedulesResp.Items for i := range schedules { - if schedules[i].Id == nil { + if schedules[i].Id == 0 { continue } - scheduleId := strconv.FormatInt(*schedules[i].Id, 10) + scheduleId := strconv.FormatInt(int64(schedules[i].Id), 10) if utils.Contains(schedulesToDestroy, scheduleId) { - err := client.DeleteBackupScheduleExecute(ctx, testutil.ProjectId, serverId, scheduleId, testutil.Region) + err := client.DefaultAPI.DeleteBackupSchedule(ctx, testutil.ProjectId, serverId, scheduleId, testutil.Region).Execute() if err != nil { return fmt.Errorf("destroying server backup schedule %s during CheckDestroy: %w", scheduleId, err) } diff --git a/stackit/internal/services/serverbackup/utils/util.go b/stackit/internal/services/serverbackup/utils/util.go index 76aa10bd3..dfdee9afa 100644 --- a/stackit/internal/services/serverbackup/utils/util.go +++ b/stackit/internal/services/serverbackup/utils/util.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/stackitcloud/stackit-sdk-go/services/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/stackitcloud/stackit-sdk-go/core/config" diff --git a/stackit/internal/services/serverbackup/utils/util_test.go b/stackit/internal/services/serverbackup/utils/util_test.go index f1769f11e..fa90da415 100644 --- a/stackit/internal/services/serverbackup/utils/util_test.go +++ b/stackit/internal/services/serverbackup/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/serverbackup" + serverbackup "github.com/stackitcloud/stackit-sdk-go/services/serverbackup/v2api" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"