Skip to content

Commit 17426a6

Browse files
committed
chore(serverupdate): use new multi API version support SDK
1 parent c64e6ce commit 17426a6

14 files changed

Lines changed: 134 additions & 128 deletions

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/stackitcloud/stackit-sdk-go/services/scf v0.6.1
3737
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.14.3
3838
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8
39-
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6
39+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.0
4040
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0
4141
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.4.1
4242
github.com/stackitcloud/stackit-sdk-go/services/sfs v0.6.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8 h1:LLyANBzE8
724724
github.com/stackitcloud/stackit-sdk-go/services/serverbackup v1.3.8/go.mod h1:/bmg57XZu+bGczzcoumrukiGMPGzI2mOyTT4BVIQUBs=
725725
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6 h1:sQ3fdtUjgIL2Ul8nRYVVacHOwi5aSMTGGbYVL30oQBU=
726726
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.2.6/go.mod h1:3fjlL+9YtuI9Oocl1ZeYIK48ImtY4DwPggFhqAygr7o=
727+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.0 h1:4MYNb3VQjVnVPfJ9xhDbSQgoSkxQZJ0tsv9N7O43/RI=
728+
github.com/stackitcloud/stackit-sdk-go/services/serverupdate v1.5.0/go.mod h1:iVCh5xZW/DHBMnJW4Zrw8KMhQIBRAETcnTPi5bbcQIE=
727729
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0 h1:l1EDIlXce2C8JcbBDHVa6nZ4SjPTqmnALTgrhms+NKI=
728730
github.com/stackitcloud/stackit-sdk-go/services/serviceaccount v0.12.0/go.mod h1:EXq8/J7t9p8zPmdIq+atuxyAbnQwxrQT18fI+Qpv98k=
729731
github.com/stackitcloud/stackit-sdk-go/services/serviceenablement v1.4.1 h1:HZnZju8yqpvRIs71PEk54Jov6p+jiKIIlN+J+4tvcL0=

stackit/internal/services/serverupdate/enable/datasource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1111
"github.com/hashicorp/terraform-plugin-framework/types"
1212
"github.com/hashicorp/terraform-plugin-log/tflog"
13-
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
13+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
1414

1515
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
1616
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
@@ -130,7 +130,7 @@ func (d *serverUpdateEnableDataSource) Read(ctx context.Context, req datasource.
130130
ctx = tflog.SetField(ctx, "server_id", serverId)
131131
ctx = tflog.SetField(ctx, "region", region)
132132

133-
serviceResp, err := d.client.GetServiceResource(ctx, projectId, serverId, region).Execute()
133+
serviceResp, err := d.client.DefaultAPI.GetServiceResource(ctx, projectId, serverId, region).Execute()
134134
if err != nil {
135135
utils.LogError(
136136
ctx,

stackit/internal/services/serverupdate/enable/datasource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/google/go-cmp/cmp"
88
"github.com/hashicorp/terraform-plugin-framework/types"
99
"github.com/stackitcloud/stackit-sdk-go/core/utils"
10-
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
10+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
1111
)
1212

1313
func TestDataMapFields(t *testing.T) {

stackit/internal/services/serverupdate/enable/resource.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1616
"github.com/hashicorp/terraform-plugin-log/tflog"
1717
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
18-
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
18+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
1919

2020
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
2121
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
@@ -189,7 +189,7 @@ func (r *serverUpdateEnableResource) Create(ctx context.Context, req resource.Cr
189189
ctx = tflog.SetField(ctx, "server_id", serverId)
190190
ctx = tflog.SetField(ctx, "region", region)
191191

192-
err := r.client.EnableServiceResource(ctx, projectId, serverId, region).EnableServiceResourcePayload(serverupdate.EnableServiceResourcePayload{}).Execute()
192+
err := r.client.DefaultAPI.EnableServiceResource(ctx, projectId, serverId, region).EnableServiceResourcePayload(serverupdate.EnableServiceResourcePayload{}).Execute()
193193
if err != nil {
194194
var oapiErr *oapierror.GenericOpenAPIError
195195
ok := errors.As(err, &oapiErr)
@@ -201,7 +201,7 @@ func (r *serverUpdateEnableResource) Create(ctx context.Context, req resource.Cr
201201
tflog.Info(ctx, "Server update is already enabled for this server. Please check duplicate resources.")
202202
}
203203

204-
serviceResp, err := r.client.GetServiceResource(ctx, projectId, serverId, region).Execute()
204+
serviceResp, err := r.client.DefaultAPI.GetServiceResource(ctx, projectId, serverId, region).Execute()
205205
if err != nil {
206206
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading server update enable", fmt.Sprintf("Calling API: %v", err))
207207
return
@@ -243,7 +243,7 @@ func (r *serverUpdateEnableResource) Read(ctx context.Context, req resource.Read
243243
ctx = tflog.SetField(ctx, "server_id", serverId)
244244
ctx = tflog.SetField(ctx, "region", region)
245245

246-
serviceResp, err := r.client.GetServiceResource(ctx, projectId, serverId, region).Execute()
246+
serviceResp, err := r.client.DefaultAPI.GetServiceResource(ctx, projectId, serverId, region).Execute()
247247
if err != nil {
248248
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
249249
if ok && oapiErr.StatusCode == http.StatusNotFound {
@@ -297,7 +297,7 @@ func (r *serverUpdateEnableResource) Delete(ctx context.Context, req resource.De
297297
ctx = tflog.SetField(ctx, "server_id", serverId)
298298
ctx = tflog.SetField(ctx, "region", region)
299299

300-
err := r.client.DisableServiceResource(ctx, projectId, serverId, region).Execute()
300+
err := r.client.DefaultAPI.DisableServiceResource(ctx, projectId, serverId, region).Execute()
301301
if err != nil {
302302
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting server update enable", fmt.Sprintf("Calling API: %v", err))
303303
return

stackit/internal/services/serverupdate/enable/resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/hashicorp/terraform-plugin-framework/types"
99

1010
"github.com/stackitcloud/stackit-sdk-go/core/utils"
11-
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
11+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
1212
)
1313

1414
func TestMapFields(t *testing.T) {

stackit/internal/services/serverupdate/schedule/resource.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"strconv"
88
"strings"
99

10+
"github.com/hashicorp/terraform-plugin-framework-validators/int32validator"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier"
1012
serverupdateUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serverupdate/utils"
1113

12-
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
1314
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1415
"github.com/hashicorp/terraform-plugin-framework/path"
1516
"github.com/hashicorp/terraform-plugin-framework/resource"
1617
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
17-
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
1818
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1919
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2020
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
@@ -28,7 +28,7 @@ import (
2828
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
2929

3030
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
31-
"github.com/stackitcloud/stackit-sdk-go/services/serverupdate"
31+
serverupdate "github.com/stackitcloud/stackit-sdk-go/services/serverupdate/v2api"
3232
)
3333

3434
// Ensure the implementation satisfies the expected interfaces.
@@ -43,11 +43,11 @@ type Model struct {
4343
ID types.String `tfsdk:"id"`
4444
ProjectId types.String `tfsdk:"project_id"`
4545
ServerId types.String `tfsdk:"server_id"`
46-
UpdateScheduleId types.Int64 `tfsdk:"update_schedule_id"`
46+
UpdateScheduleId types.Int32 `tfsdk:"update_schedule_id"`
4747
Name types.String `tfsdk:"name"`
4848
Rrule types.String `tfsdk:"rrule"`
4949
Enabled types.Bool `tfsdk:"enabled"`
50-
MaintenanceWindow types.Int64 `tfsdk:"maintenance_window"`
50+
MaintenanceWindow types.Int32 `tfsdk:"maintenance_window"`
5151
Region types.String `tfsdk:"region"`
5252
}
5353

@@ -136,14 +136,14 @@ func (r *scheduleResource) Schema(_ context.Context, _ resource.SchemaRequest, r
136136
stringvalidator.LengthBetween(1, 255),
137137
},
138138
},
139-
"update_schedule_id": schema.Int64Attribute{
139+
"update_schedule_id": schema.Int32Attribute{
140140
Description: "Update schedule ID.",
141141
Computed: true,
142-
PlanModifiers: []planmodifier.Int64{
143-
int64planmodifier.UseStateForUnknown(),
142+
PlanModifiers: []planmodifier.Int32{
143+
int32planmodifier.UseStateForUnknown(),
144144
},
145-
Validators: []validator.Int64{
146-
int64validator.AtLeast(1),
145+
Validators: []validator.Int32{
146+
int32validator.AtLeast(1),
147147
},
148148
},
149149
"project_id": schema.StringAttribute{
@@ -186,12 +186,12 @@ func (r *scheduleResource) Schema(_ context.Context, _ resource.SchemaRequest, r
186186
Description: "Is the update schedule enabled or disabled.",
187187
Required: true,
188188
},
189-
"maintenance_window": schema.Int64Attribute{
189+
"maintenance_window": schema.Int32Attribute{
190190
Description: "Maintenance window [1..24]. Updates start within the defined hourly window. Depending on the updates, the process may exceed this timeframe and require an automatic restart.",
191191
Required: true,
192-
Validators: []validator.Int64{
193-
int64validator.AtLeast(1),
194-
int64validator.AtMost(24),
192+
Validators: []validator.Int32{
193+
int32validator.AtLeast(1),
194+
int32validator.AtMost(24),
195195
},
196196
},
197197
"region": schema.StringAttribute{
@@ -244,15 +244,15 @@ func (r *scheduleResource) Create(ctx context.Context, req resource.CreateReques
244244
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating server update schedule", fmt.Sprintf("Creating API payload: %v", err))
245245
return
246246
}
247-
scheduleResp, err := r.client.CreateUpdateSchedule(ctx, projectId, serverId, region).CreateUpdateSchedulePayload(*payload).Execute()
247+
scheduleResp, err := r.client.DefaultAPI.CreateUpdateSchedule(ctx, projectId, serverId, region).CreateUpdateSchedulePayload(*payload).Execute()
248248
if err != nil {
249249
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating server update schedule", fmt.Sprintf("Calling API: %v", err))
250250
return
251251
}
252252

253253
ctx = core.LogResponse(ctx)
254254

255-
ctx = tflog.SetField(ctx, "update_schedule_id", *scheduleResp.Id)
255+
ctx = tflog.SetField(ctx, "update_schedule_id", scheduleResp.Id)
256256

257257
// Map response body to schema
258258
err = mapFields(scheduleResp, &model, region)
@@ -281,14 +281,14 @@ func (r *scheduleResource) Read(ctx context.Context, req resource.ReadRequest, r
281281

282282
projectId := model.ProjectId.ValueString()
283283
serverId := model.ServerId.ValueString()
284-
updateScheduleId := model.UpdateScheduleId.ValueInt64()
284+
updateScheduleId := model.UpdateScheduleId.ValueInt32()
285285
region := r.providerData.GetRegionWithOverride(model.Region)
286286
ctx = tflog.SetField(ctx, "project_id", projectId)
287287
ctx = tflog.SetField(ctx, "server_id", serverId)
288288
ctx = tflog.SetField(ctx, "region", region)
289289
ctx = tflog.SetField(ctx, "update_schedule_id", updateScheduleId)
290290

291-
scheduleResp, err := r.client.GetUpdateSchedule(ctx, projectId, serverId, strconv.FormatInt(updateScheduleId, 10), region).Execute()
291+
scheduleResp, err := r.client.DefaultAPI.GetUpdateSchedule(ctx, projectId, serverId, strconv.FormatInt(int64(updateScheduleId), 10), region).Execute()
292292
if err != nil {
293293
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
294294
if ok && oapiErr.StatusCode == http.StatusNotFound {
@@ -330,7 +330,7 @@ func (r *scheduleResource) Update(ctx context.Context, req resource.UpdateReques
330330

331331
projectId := model.ProjectId.ValueString()
332332
serverId := model.ServerId.ValueString()
333-
updateScheduleId := model.UpdateScheduleId.ValueInt64()
333+
updateScheduleId := model.UpdateScheduleId.ValueInt32()
334334
region := model.Region.ValueString()
335335
ctx = tflog.SetField(ctx, "project_id", projectId)
336336
ctx = tflog.SetField(ctx, "server_id", serverId)
@@ -344,7 +344,7 @@ func (r *scheduleResource) Update(ctx context.Context, req resource.UpdateReques
344344
return
345345
}
346346

347-
scheduleResp, err := r.client.UpdateUpdateSchedule(ctx, projectId, serverId, strconv.FormatInt(updateScheduleId, 10), region).UpdateUpdateSchedulePayload(*payload).Execute()
347+
scheduleResp, err := r.client.DefaultAPI.UpdateUpdateSchedule(ctx, projectId, serverId, strconv.FormatInt(int64(updateScheduleId), 10), region).UpdateUpdateSchedulePayload(*payload).Execute()
348348
if err != nil {
349349
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating server update schedule", fmt.Sprintf("Calling API: %v", err))
350350
return
@@ -379,14 +379,14 @@ func (r *scheduleResource) Delete(ctx context.Context, req resource.DeleteReques
379379

380380
projectId := model.ProjectId.ValueString()
381381
serverId := model.ServerId.ValueString()
382-
updateScheduleId := model.UpdateScheduleId.ValueInt64()
382+
updateScheduleId := model.UpdateScheduleId.ValueInt32()
383383
region := model.Region.ValueString()
384384
ctx = tflog.SetField(ctx, "project_id", projectId)
385385
ctx = tflog.SetField(ctx, "server_id", serverId)
386386
ctx = tflog.SetField(ctx, "region", region)
387387
ctx = tflog.SetField(ctx, "update_schedule_id", updateScheduleId)
388388

389-
err := r.client.DeleteUpdateSchedule(ctx, projectId, serverId, strconv.FormatInt(updateScheduleId, 10), region).Execute()
389+
err := r.client.DefaultAPI.DeleteUpdateSchedule(ctx, projectId, serverId, strconv.FormatInt(int64(updateScheduleId), 10), region).Execute()
390390
if err != nil {
391391
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting server update schedule", fmt.Sprintf("Calling API: %v", err))
392392
return
@@ -432,19 +432,19 @@ func mapFields(schedule *serverupdate.UpdateSchedule, model *Model, region strin
432432
if model == nil {
433433
return fmt.Errorf("model input is nil")
434434
}
435-
if schedule.Id == nil {
436-
return fmt.Errorf("response id is nil")
435+
if schedule.Id == 0 {
436+
return fmt.Errorf("response id is 0")
437437
}
438438

439-
model.UpdateScheduleId = types.Int64PointerValue(schedule.Id)
439+
model.UpdateScheduleId = types.Int32Value(schedule.Id)
440440
model.ID = utils.BuildInternalTerraformId(
441441
model.ProjectId.ValueString(), region, model.ServerId.ValueString(),
442-
strconv.FormatInt(model.UpdateScheduleId.ValueInt64(), 10),
442+
strconv.FormatInt(int64(model.UpdateScheduleId.ValueInt32()), 10),
443443
)
444-
model.Name = types.StringPointerValue(schedule.Name)
445-
model.Rrule = types.StringPointerValue(schedule.Rrule)
446-
model.Enabled = types.BoolPointerValue(schedule.Enabled)
447-
model.MaintenanceWindow = types.Int64PointerValue(schedule.MaintenanceWindow)
444+
model.Name = types.StringValue(schedule.Name)
445+
model.Rrule = types.StringValue(schedule.Rrule)
446+
model.Enabled = types.BoolValue(schedule.Enabled)
447+
model.MaintenanceWindow = types.Int32Value(schedule.MaintenanceWindow)
448448
model.Region = types.StringValue(region)
449449
return nil
450450
}
@@ -458,7 +458,7 @@ func enableUpdatesService(ctx context.Context, model *Model, client *serverupdat
458458
payload := serverupdate.EnableServiceResourcePayload{}
459459

460460
tflog.Debug(ctx, "Enabling server update service")
461-
err := client.EnableServiceResource(ctx, projectId, serverId, region).EnableServiceResourcePayload(payload).Execute()
461+
err := client.DefaultAPI.EnableServiceResource(ctx, projectId, serverId, region).EnableServiceResourcePayload(payload).Execute()
462462
if err != nil {
463463
if strings.Contains(err.Error(), "Tried to activate already active service") {
464464
tflog.Debug(ctx, "Service for server update already enabled")
@@ -476,10 +476,10 @@ func toCreatePayload(model *Model) (*serverupdate.CreateUpdateSchedulePayload, e
476476
}
477477

478478
return &serverupdate.CreateUpdateSchedulePayload{
479-
Enabled: conversion.BoolValueToPointer(model.Enabled),
480-
Name: conversion.StringValueToPointer(model.Name),
481-
Rrule: conversion.StringValueToPointer(model.Rrule),
482-
MaintenanceWindow: conversion.Int64ValueToPointer(model.MaintenanceWindow),
479+
Enabled: model.Enabled.ValueBool(),
480+
Name: model.Name.ValueString(),
481+
Rrule: model.Rrule.ValueString(),
482+
MaintenanceWindow: model.MaintenanceWindow.ValueInt32(),
483483
}, nil
484484
}
485485

@@ -489,9 +489,9 @@ func toUpdatePayload(model *Model) (*serverupdate.UpdateUpdateSchedulePayload, e
489489
}
490490

491491
return &serverupdate.UpdateUpdateSchedulePayload{
492-
Enabled: conversion.BoolValueToPointer(model.Enabled),
493-
Name: conversion.StringValueToPointer(model.Name),
494-
Rrule: conversion.StringValueToPointer(model.Rrule),
495-
MaintenanceWindow: conversion.Int64ValueToPointer(model.MaintenanceWindow),
492+
Enabled: model.Enabled.ValueBool(),
493+
Name: model.Name.ValueString(),
494+
Rrule: model.Rrule.ValueString(),
495+
MaintenanceWindow: model.MaintenanceWindow.ValueInt32(),
496496
}, nil
497497
}

0 commit comments

Comments
 (0)