@@ -19,13 +19,13 @@ import (
1919 "github.com/hashicorp/terraform-plugin-framework/schema/validator"
2020 "github.com/hashicorp/terraform-plugin-framework/types"
2121 "github.com/hashicorp/terraform-plugin-log/tflog"
22- "github.com/stackitcloud/stackit-sdk-go/core/config"
2322 "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
2423 "github.com/stackitcloud/stackit-sdk-go/services/sfs"
2524 "github.com/stackitcloud/stackit-sdk-go/services/sfs/wait"
2625 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
2726 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
2827 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
28+ sfsUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sfs/utils"
2929 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
3030 coreutils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
3131 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
@@ -121,26 +121,10 @@ func (r *resourcePoolResource) Configure(ctx context.Context, req resource.Confi
121121 datasourceBetaCheckDone = true
122122 }
123123
124- var apiClient * sfs.APIClient
125- var err error
126- if r .providerData .SfsCustomEndpoint != "" {
127- ctx = tflog .SetField (ctx , "sfs_custom_endpoint" , r .providerData .SfsCustomEndpoint )
128- apiClient , err = sfs .NewAPIClient (
129- config .WithCustomAuth (r .providerData .RoundTripper ),
130- config .WithEndpoint (r .providerData .SfsCustomEndpoint ),
131- )
132- } else {
133- apiClient , err = sfs .NewAPIClient (
134- config .WithCustomAuth (r .providerData .RoundTripper ),
135- config .WithRegion (r .providerData .GetRegion ()),
136- )
137- }
138-
139- if err != nil {
140- core .LogAndAddError (ctx , & resp .Diagnostics , "Error configuring API client" , fmt .Sprintf ("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration" , err ))
124+ apiClient := sfsUtils .ConfigureClient (ctx , & r .providerData , & resp .Diagnostics )
125+ if resp .Diagnostics .HasError () {
141126 return
142127 }
143-
144128 r .client = apiClient
145129 tflog .Info (ctx , "SFS client configured" )
146130}
@@ -248,6 +232,8 @@ func (r *resourcePoolResource) Create(ctx context.Context, req resource.CreateRe
248232 ctx = tflog .SetField (ctx , "project_id" , projectId )
249233 ctx = tflog .SetField (ctx , "region" , region )
250234
235+ ctx = core .InitProviderContext (ctx )
236+
251237 payload , err := toCreatePayload (& model )
252238 if err != nil {
253239 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating resource pool" , fmt .Sprintf ("Cannot create payload: %v" , err ))
@@ -262,7 +248,9 @@ func (r *resourcePoolResource) Create(ctx context.Context, req resource.CreateRe
262248 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating resource pool" , fmt .Sprintf ("Calling API: %v" , err ))
263249 return
264250 }
265- // TODO: log traceId
251+
252+ ctx = core .LogResponse (ctx )
253+
266254 if resourcePool == nil || resourcePool .ResourcePool == nil || resourcePool .ResourcePool .Id == nil {
267255 core .LogAndAddError (ctx , & resp .Diagnostics , "error creating resource pool" , "Calling API: Incomplete response (id missing)" )
268256 return
@@ -330,6 +318,8 @@ func (r *resourcePoolResource) Read(ctx context.Context, req resource.ReadReques
330318 ctx = tflog .SetField (ctx , "resource_pool_id" , resourcePoolId )
331319 ctx = tflog .SetField (ctx , "region" , region )
332320
321+ ctx = core .InitProviderContext (ctx )
322+
333323 response , err := r .client .GetResourcePoolExecute (ctx , projectId , region , resourcePoolId )
334324 if err != nil {
335325 var openapiError * oapierror.GenericOpenAPIError
@@ -342,7 +332,8 @@ func (r *resourcePoolResource) Read(ctx context.Context, req resource.ReadReques
342332 core .LogAndAddError (ctx , & resp .Diagnostics , "Error reading resource pool" , fmt .Sprintf ("Calling API: %v" , err ))
343333 return
344334 }
345- // TODO: log traceId
335+
336+ ctx = core .LogResponse (ctx )
346337
347338 // Map response body to schema
348339 err = mapFields (ctx , region , response .ResourcePool , & model )
@@ -375,6 +366,8 @@ func (r *resourcePoolResource) Update(ctx context.Context, req resource.UpdateRe
375366 ctx = tflog .SetField (ctx , "resource_pool_id" , resourcePoolId )
376367 ctx = tflog .SetField (ctx , "region" , region )
377368
369+ ctx = core .InitProviderContext (ctx )
370+
378371 // Retrieve values from state
379372 var stateModel Model
380373 diags = req .State .Get (ctx , & stateModel )
@@ -403,7 +396,9 @@ func (r *resourcePoolResource) Update(ctx context.Context, req resource.UpdateRe
403396 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating resource pool" , fmt .Sprintf ("Calling API: %v" , err ))
404397 return
405398 }
406- // TODO: log traceId
399+
400+ ctx = core .LogResponse (ctx )
401+
407402 // the responses of create and update are not compatible, so we can't use a unified
408403 // mapFields function. Therefore, we issue a GET request after the create
409404 // to get a compatible structure
@@ -447,13 +442,17 @@ func (r *resourcePoolResource) Delete(ctx context.Context, req resource.DeleteRe
447442 ctx = tflog .SetField (ctx , "resource_pool_id" , resourcePoolId )
448443 ctx = tflog .SetField (ctx , "region" , region )
449444
445+ ctx = core .InitProviderContext (ctx )
446+
450447 // Delete existing resource pool
451448 _ , err := r .client .DeleteResourcePoolExecute (ctx , projectId , region , resourcePoolId )
452449 if err != nil {
453450 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting resource pool" , fmt .Sprintf ("Calling API: %v" , err ))
454451 return
455452 }
456- // TODO: log traceId
453+
454+ ctx = core .LogResponse (ctx )
455+
457456 // only delete, if no error occurred
458457 _ , err = wait .DeleteResourcePoolWaitHandler (ctx , r .client , projectId , region , resourcePoolId ).WaitWithContext (ctx )
459458 if err != nil {
0 commit comments