@@ -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