@@ -31,7 +31,7 @@ import (
3131 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
3232
3333 "github.com/hashicorp/terraform-plugin-framework/resource"
34- "github.com/stackitcloud/stackit-sdk-go/services/sfs"
34+ sfs "github.com/stackitcloud/stackit-sdk-go/services/sfs/v1api "
3535)
3636
3737// Ensure the implementation satisfies the expected interfaces.
@@ -54,7 +54,7 @@ type Model struct {
5454type rulesModel struct {
5555 Description types.String `tfsdk:"description"`
5656 IpAcl types.List `tfsdk:"ip_acl"`
57- Order types.Int64 `tfsdk:"order"`
57+ Order types.Int32 `tfsdk:"order"`
5858 ReadOnly types.Bool `tfsdk:"read_only"`
5959 SetUuid types.Bool `tfsdk:"set_uuid"`
6060 SuperUser types.Bool `tfsdk:"super_user"`
@@ -64,7 +64,7 @@ type rulesModel struct {
6464var rulesTypes = map [string ]attr.Type {
6565 "description" : types .StringType ,
6666 "ip_acl" : types.ListType {ElemType : types .StringType },
67- "order" : types .Int64Type ,
67+ "order" : types .Int32Type ,
6868 "read_only" : types .BoolType ,
6969 "set_uuid" : types .BoolType ,
7070 "super_user" : types .BoolType ,
@@ -206,7 +206,7 @@ func (r *exportPolicyResource) Schema(_ context.Context, _ resource.SchemaReques
206206 listvalidator .ValueStringsAre (validate .CIDR ()),
207207 },
208208 },
209- "order" : schema.Int64Attribute {
209+ "order" : schema.Int32Attribute {
210210 Description : "Order of the rule within a Share Export Policy. The order is used so that when a client IP matches multiple rules, the first rule is applied" ,
211211 Required : true ,
212212 },
@@ -275,7 +275,7 @@ func (r *exportPolicyResource) Create(ctx context.Context, req resource.CreateRe
275275 return
276276 }
277277
278- createResp , err := r .client .CreateShareExportPolicy (ctx , projectId , region ).CreateShareExportPolicyPayload (* payload ).Execute ()
278+ createResp , err := r .client .DefaultAPI . CreateShareExportPolicy (ctx , projectId , region ).CreateShareExportPolicyPayload (* payload ).Execute ()
279279 if err != nil {
280280 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating export policy" , fmt .Sprintf ("Calling API: %v" , err ))
281281 return
@@ -298,7 +298,7 @@ func (r *exportPolicyResource) Create(ctx context.Context, req resource.CreateRe
298298 }
299299
300300 // get export policy
301- getResp , err := r .client .GetShareExportPolicy (ctx , projectId , region , * createResp .ShareExportPolicy .Id ).Execute ()
301+ getResp , err := r .client .DefaultAPI . GetShareExportPolicy (ctx , projectId , region , * createResp .ShareExportPolicy .Id ).Execute ()
302302 if err != nil {
303303 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating export policy" , fmt .Sprintf ("Calling API to get export policy: %v" , err ))
304304 return
@@ -337,7 +337,7 @@ func (r *exportPolicyResource) Read(ctx context.Context, req resource.ReadReques
337337 ctx = core .InitProviderContext (ctx )
338338
339339 // get export policy
340- exportPolicyResp , err := r .client .GetShareExportPolicy (ctx , projectId , region , exportPolicyId ).Execute ()
340+ exportPolicyResp , err := r .client .DefaultAPI . GetShareExportPolicy (ctx , projectId , region , exportPolicyId ).Execute ()
341341 if err != nil {
342342 var openapiError * oapierror.GenericOpenAPIError
343343 if errors .As (err , & openapiError ) {
@@ -401,7 +401,7 @@ func (r *exportPolicyResource) Update(ctx context.Context, req resource.UpdateRe
401401 return
402402 }
403403
404- _ , err = r .client .UpdateShareExportPolicy (ctx , projectId , region , exportPolicyId ).UpdateShareExportPolicyPayload (* payload ).Execute ()
404+ _ , err = r .client .DefaultAPI . UpdateShareExportPolicy (ctx , projectId , region , exportPolicyId ).UpdateShareExportPolicyPayload (* payload ).Execute ()
405405 if err != nil {
406406 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating export policy" , fmt .Sprintf ("Calling API to update export policy: %v" , err ))
407407 return
@@ -410,7 +410,7 @@ func (r *exportPolicyResource) Update(ctx context.Context, req resource.UpdateRe
410410 ctx = core .LogResponse (ctx )
411411
412412 // get export policy
413- exportPolicyResp , err := r .client .GetShareExportPolicy (ctx , projectId , region , exportPolicyId ).Execute ()
413+ exportPolicyResp , err := r .client .DefaultAPI . GetShareExportPolicy (ctx , projectId , region , exportPolicyId ).Execute ()
414414 if err != nil {
415415 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating export policy" , fmt .Sprintf ("Calling API to get export policy: %v" , err ))
416416 return
@@ -450,7 +450,7 @@ func (r *exportPolicyResource) Delete(ctx context.Context, req resource.DeleteRe
450450
451451 ctx = core .InitProviderContext (ctx )
452452
453- _ , err := r .client .DeleteShareExportPolicy (ctx , projectId , region , exportPolicyId ).Execute ()
453+ _ , err := r .client .DefaultAPI . DeleteShareExportPolicy (ctx , projectId , region , exportPolicyId ).Execute ()
454454 if err != nil {
455455 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting export policy" , fmt .Sprintf ("Calling API: %v" , err ))
456456 }
@@ -502,7 +502,7 @@ func mapFields(ctx context.Context, resp *sfs.GetShareExportPolicyResponse, mode
502502 // iterate over Rules from response
503503 if resp .ShareExportPolicy .Rules != nil {
504504 rulesList := []attr.Value {}
505- for _ , rule := range * resp .ShareExportPolicy .Rules {
505+ for _ , rule := range resp .ShareExportPolicy .Rules {
506506 var ipAcl basetypes.ListValue
507507 if rule .IpAcl != nil {
508508 var diags diag.Diagnostics
@@ -515,9 +515,9 @@ func mapFields(ctx context.Context, resp *sfs.GetShareExportPolicyResponse, mode
515515 }
516516
517517 rulesValues := map [string ]attr.Value {
518- "description" : types .StringPointerValue (rule .GetDescription ()),
518+ "description" : types .StringPointerValue (rule .Description . Get ()),
519519 "ip_acl" : ipAcl ,
520- "order" : types .Int64PointerValue (rule .Order ),
520+ "order" : types .Int32PointerValue (rule .Order ),
521521 "read_only" : types .BoolPointerValue (rule .ReadOnly ),
522522 "set_uuid" : types .BoolPointerValue (rule .SetUuid ),
523523 "super_user" : types .BoolPointerValue (rule .SuperUser ),
@@ -564,14 +564,14 @@ func toCreatePayload(model *Model, rules []rulesModel) (*sfs.CreateShareExportPo
564564 var tempRules []sfs.CreateShareExportPolicyRequestRule
565565 for _ , rule := range rules {
566566 // convert list
567- convertedList , err := conversion .StringListToPointer (rule .IpAcl )
567+ convertedList , err := conversion .StringListToSlice (rule .IpAcl )
568568 if err != nil {
569569 return nil , fmt .Errorf ("conversion of rule failed" )
570570 }
571571 tempRule := sfs.CreateShareExportPolicyRequestRule {
572- Description : sfs .NewNullableString (conversion .StringValueToPointer (rule .Description )),
572+ Description : * sfs .NewNullableString (conversion .StringValueToPointer (rule .Description )),
573573 IpAcl : convertedList ,
574- Order : conversion .Int64ValueToPointer (rule .Order ),
574+ Order : conversion .Int32ValueToPointer (rule .Order ),
575575 ReadOnly : conversion .BoolValueToPointer (rule .ReadOnly ),
576576 SetUuid : conversion .BoolValueToPointer (rule .SetUuid ),
577577 SuperUser : conversion .BoolValueToPointer (rule .SuperUser ),
@@ -581,12 +581,12 @@ func toCreatePayload(model *Model, rules []rulesModel) (*sfs.CreateShareExportPo
581581
582582 // name and rules
583583 result := & sfs.CreateShareExportPolicyPayload {
584- Name : model .Name .ValueStringPointer (),
584+ Name : model .Name .ValueString (),
585585 }
586586
587587 // Rules should only be set if tempRules has value. Otherwise, the payload would contain `{ "rules": null }` what should be prevented
588588 if tempRules != nil {
589- result .Rules = & tempRules
589+ result .Rules = tempRules
590590 }
591591
592592 return result , nil
@@ -604,14 +604,14 @@ func toUpdatePayload(model *Model, rules []rulesModel) (*sfs.UpdateShareExportPo
604604 tempRules := make ([]sfs.UpdateShareExportPolicyBodyRule , len (rules ))
605605 for i , rule := range rules {
606606 // convert list
607- convertedList , err := conversion .StringListToPointer (rule .IpAcl )
607+ convertedList , err := conversion .StringListToSlice (rule .IpAcl )
608608 if err != nil {
609609 return nil , fmt .Errorf ("conversion of rule failed" )
610610 }
611611 tempRule := sfs.UpdateShareExportPolicyBodyRule {
612- Description : sfs .NewNullableString (conversion .StringValueToPointer (rule .Description )),
612+ Description : * sfs .NewNullableString (conversion .StringValueToPointer (rule .Description )),
613613 IpAcl : convertedList ,
614- Order : conversion .Int64ValueToPointer (rule .Order ),
614+ Order : conversion .Int32ValueToPointer (rule .Order ),
615615 ReadOnly : conversion .BoolValueToPointer (rule .ReadOnly ),
616616 SetUuid : conversion .BoolValueToPointer (rule .SetUuid ),
617617 SuperUser : conversion .BoolValueToPointer (rule .SuperUser ),
@@ -623,7 +623,7 @@ func toUpdatePayload(model *Model, rules []rulesModel) (*sfs.UpdateShareExportPo
623623 result := & sfs.UpdateShareExportPolicyPayload {
624624 // Rules should *+never** result in a payload where they are defined as null, e.g. `{ "rules": null }`. Instead,
625625 // they should either be set to an array (with values or empty) or they shouldn't be present in the payload.
626- Rules : & tempRules ,
626+ Rules : tempRules ,
627627 }
628628 return result , nil
629629}
0 commit comments