@@ -23,8 +23,7 @@ import (
2323 "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
2424 "github.com/hashicorp/terraform-plugin-log/tflog"
2525 "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
26- sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
27- "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager"
26+ resourcemanager "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager/v0api"
2827 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
2928 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
3029 resourcemanagerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/resourcemanager/utils"
@@ -86,6 +85,7 @@ func (r *folderResource) Configure(ctx context.Context, req resource.ConfigureRe
8685 return
8786 }
8887 r .client = apiClient
88+
8989 tflog .Info (ctx , "Resource Manager client configured" )
9090}
9191
@@ -206,21 +206,21 @@ func (r *folderResource) Create(ctx context.Context, req resource.CreateRequest,
206206 return
207207 }
208208
209- folderCreateResp , err := r .client .CreateFolder (ctx ).CreateFolderPayload (* payload ).Execute ()
209+ folderCreateResp , err := r .client .DefaultAPI . CreateFolder (ctx ).CreateFolderPayload (* payload ).Execute ()
210210 if err != nil {
211211 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating folder" , fmt .Sprintf ("Calling API: %v" , err ))
212212 return
213213 }
214214
215215 ctx = core .LogResponse (ctx )
216216
217- if folderCreateResp .ContainerId == nil || * folderCreateResp . ContainerId == "" {
217+ if folderCreateResp .ContainerId == "" {
218218 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating folder" , "Container ID is missing" )
219219 return
220220 }
221221
222222 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
223- "container_id" : * folderCreateResp .ContainerId ,
223+ "container_id" : folderCreateResp .ContainerId ,
224224 })
225225
226226 select {
@@ -230,7 +230,7 @@ func (r *folderResource) Create(ctx context.Context, req resource.CreateRequest,
230230 // continue
231231 }
232232
233- folderGetResponse , err := r .client .GetFolderDetails (ctx , * folderCreateResp .ContainerId ).Execute ()
233+ folderGetResponse , err := r .client .DefaultAPI . GetFolderDetails (ctx , folderCreateResp .ContainerId ).Execute ()
234234 if err != nil {
235235 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating folder" , fmt .Sprintf ("Calling API: %v" , err ))
236236 return
@@ -262,7 +262,7 @@ func (r *folderResource) Read(ctx context.Context, req resource.ReadRequest, res
262262 ctx = tflog .SetField (ctx , "folder_name" , folderName )
263263 ctx = tflog .SetField (ctx , "container_id" , containerId )
264264
265- folderResp , err := r .client .GetFolderDetails (ctx , containerId ).Execute ()
265+ folderResp , err := r .client .DefaultAPI . GetFolderDetails (ctx , containerId ).Execute ()
266266 if err != nil {
267267 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
268268 if ok && oapiErr .StatusCode == http .StatusForbidden {
@@ -312,7 +312,7 @@ func (r *folderResource) Update(ctx context.Context, req resource.UpdateRequest,
312312 return
313313 }
314314 // Update existing folder
315- _ , err = r .client .PartialUpdateFolder (ctx , containerId ).PartialUpdateFolderPayload (* payload ).Execute ()
315+ _ , err = r .client .DefaultAPI . PartialUpdateFolder (ctx , containerId ).PartialUpdateFolderPayload (* payload ).Execute ()
316316 if err != nil {
317317 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating folder" , fmt .Sprintf ("Calling API: %v" , err ))
318318 return
@@ -321,7 +321,7 @@ func (r *folderResource) Update(ctx context.Context, req resource.UpdateRequest,
321321 ctx = core .LogResponse (ctx )
322322
323323 // Fetch updated folder
324- folderResp , err := r .client .GetFolderDetails (ctx , containerId ).Execute ()
324+ folderResp , err := r .client .DefaultAPI . GetFolderDetails (ctx , containerId ).Execute ()
325325 if err != nil {
326326 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating folder" , fmt .Sprintf ("Calling API for updated data: %v" , err ))
327327 return
@@ -357,7 +357,7 @@ func (r *folderResource) Delete(ctx context.Context, req resource.DeleteRequest,
357357 ctx = tflog .SetField (ctx , "container_id" , containerId )
358358
359359 // Delete existing folder
360- err := r .client .DeleteFolder (ctx , containerId ).Execute ()
360+ err := r .client .DefaultAPI . DeleteFolder (ctx , containerId ).Execute ()
361361 if err != nil {
362362 core .LogAndAddError (
363363 ctx ,
@@ -405,17 +405,17 @@ func mapFolderFields(
405405 var folderId string
406406 if model .FolderId .ValueString () != "" {
407407 folderId = model .FolderId .ValueString ()
408- } else if folderGetResponse .FolderId != nil {
409- folderId = * folderGetResponse .FolderId
408+ } else if folderGetResponse .FolderId != "" {
409+ folderId = folderGetResponse .FolderId
410410 } else {
411411 return fmt .Errorf ("folder id not present" )
412412 }
413413
414414 var containerId string
415415 if model .ContainerId .ValueString () != "" {
416416 containerId = model .ContainerId .ValueString ()
417- } else if folderGetResponse .ContainerId != nil {
418- containerId = * folderGetResponse .ContainerId
417+ } else if folderGetResponse .ContainerId != "" {
418+ containerId = folderGetResponse .ContainerId
419419 } else {
420420 return fmt .Errorf ("container id not present" )
421421 }
@@ -431,24 +431,20 @@ func mapFolderFields(
431431 tfLabels = types .MapNull (types .StringType )
432432 }
433433
434- var containerParentIdTF basetypes.StringValue
435- if folderGetResponse .Parent != nil {
436- if _ , err := uuid .Parse (model .ContainerParentId .ValueString ()); err == nil {
437- // the provided containerParent is the UUID identifier
438- containerParentIdTF = types .StringPointerValue (folderGetResponse .Parent .Id )
439- } else {
440- // the provided containerParent is the user-friendly container id
441- containerParentIdTF = types .StringPointerValue (folderGetResponse .Parent .ContainerId )
442- }
434+ var containerParentIdTF types.String
435+ if _ , err := uuid .Parse (model .ContainerParentId .ValueString ()); err == nil {
436+ // the provided containerParent is the UUID identifier
437+ containerParentIdTF = types .StringValue (folderGetResponse .Parent .Id )
443438 } else {
444- containerParentIdTF = types .StringNull ()
439+ // the provided containerParent is the user-friendly container id
440+ containerParentIdTF = types .StringValue (folderGetResponse .Parent .ContainerId )
445441 }
446442
447443 model .Id = types .StringValue (containerId )
448444 model .FolderId = types .StringValue (folderId )
449445 model .ContainerId = types .StringValue (containerId )
450446 model .ContainerParentId = containerParentIdTF
451- model .Name = types .StringPointerValue (folderGetResponse .Name )
447+ model .Name = types .StringValue (folderGetResponse .Name )
452448 model .Labels = tfLabels
453449 model .CreationTime = types .StringValue (folderGetResponse .CreationTime .Format (time .RFC3339 ))
454450 model .UpdateTime = types .StringValue (folderGetResponse .UpdateTime .Format (time .RFC3339 ))
@@ -471,18 +467,18 @@ func mapFolderFields(
471467 return nil
472468}
473469
474- func toMembersPayload (model * ResourceModel ) (* []resourcemanager.Member , error ) {
470+ func toMembersPayload (model * ResourceModel ) ([]resourcemanager.Member , error ) {
475471 if model == nil {
476472 return nil , fmt .Errorf ("nil model" )
477473 }
478474 if model .OwnerEmail .IsNull () {
479475 return nil , fmt .Errorf ("owner_email is null" )
480476 }
481477
482- return & []resourcemanager.Member {
478+ return []resourcemanager.Member {
483479 {
484- Subject : model .OwnerEmail .ValueStringPointer (),
485- Role : sdkUtils . Ptr ( projectOwnerRole ) ,
480+ Subject : model .OwnerEmail .ValueString (),
481+ Role : projectOwnerRole ,
486482 },
487483 }, nil
488484}
@@ -504,10 +500,10 @@ func toCreatePayload(model *ResourceModel) (*resourcemanager.CreateFolderPayload
504500 }
505501
506502 return & resourcemanager.CreateFolderPayload {
507- ContainerParentId : conversion . StringValueToPointer ( model .ContainerParentId ),
503+ ContainerParentId : model .ContainerParentId . ValueString ( ),
508504 Labels : labels ,
509505 Members : members ,
510- Name : conversion . StringValueToPointer ( model .Name ),
506+ Name : model .Name . ValueString ( ),
511507 }, nil
512508}
513509
0 commit comments