@@ -18,8 +18,8 @@ import (
1818 "github.com/hashicorp/terraform-plugin-framework/types"
1919 "github.com/hashicorp/terraform-plugin-log/tflog"
2020 "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
21- "github.com/stackitcloud/stackit-sdk-go/services/git"
22- "github.com/stackitcloud/stackit-sdk-go/services/git/wait"
21+ git "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi "
22+ "github.com/stackitcloud/stackit-sdk-go/services/git/v1betaapi/ wait"
2323 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
2424 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
2525 "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
@@ -209,7 +209,7 @@ func (g *gitResource) Create(ctx context.Context, req resource.CreateRequest, re
209209 }
210210
211211 // Create the new git instance via the API client.
212- gitInstanceResp , err := g .client .CreateInstance (ctx , projectId ).
212+ gitInstanceResp , err := g .client .DefaultAPI . CreateInstance (ctx , projectId ).
213213 CreateInstancePayload (payload ).
214214 Execute ()
215215 if err != nil {
@@ -219,12 +219,7 @@ func (g *gitResource) Create(ctx context.Context, req resource.CreateRequest, re
219219
220220 ctx = core .LogResponse (ctx )
221221
222- if gitInstanceResp .Id == nil {
223- core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating git instance" , "Got empty git instance id" )
224- return
225- }
226-
227- gitInstanceId := * gitInstanceResp .Id
222+ gitInstanceId := gitInstanceResp .Id
228223 // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
229224 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
230225 "project_id" : projectId ,
@@ -234,7 +229,7 @@ func (g *gitResource) Create(ctx context.Context, req resource.CreateRequest, re
234229 return
235230 }
236231
237- _ , err = wait .CreateGitInstanceWaitHandler (ctx , g .client , projectId , gitInstanceId ).WaitWithContext (ctx )
232+ _ , err = wait .CreateGitInstanceWaitHandler (ctx , g .client . DefaultAPI , projectId , gitInstanceId ).WaitWithContext (ctx )
238233 if err != nil {
239234 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating git instance" , fmt .Sprintf ("Git instance creation waiting: %v" , err ))
240235 return
@@ -272,7 +267,7 @@ func (g *gitResource) Read(ctx context.Context, req resource.ReadRequest, resp *
272267 instanceId := model .InstanceId .ValueString ()
273268
274269 // Read the current git instance via id
275- gitInstanceResp , err := g .client .GetInstance (ctx , projectId , instanceId ).Execute ()
270+ gitInstanceResp , err := g .client .DefaultAPI . GetInstance (ctx , projectId , instanceId ).Execute ()
276271 if err != nil {
277272 var oapiErr * oapierror.GenericOpenAPIError
278273 ok := errors .As (err , & oapiErr )
@@ -327,15 +322,15 @@ func (g *gitResource) Delete(ctx context.Context, req resource.DeleteRequest, re
327322 ctx = tflog .SetField (ctx , "instance_id" , instanceId )
328323
329324 // Call API to delete the existing git instance.
330- err := g .client .DeleteInstance (ctx , projectId , instanceId ).Execute ()
325+ err := g .client .DefaultAPI . DeleteInstance (ctx , projectId , instanceId ).Execute ()
331326 if err != nil {
332327 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting git instance" , fmt .Sprintf ("Calling API: %v" , err ))
333328 return
334329 }
335330
336331 ctx = core .LogResponse (ctx )
337332
338- _ , err = wait .DeleteGitInstanceWaitHandler (ctx , g .client , projectId , instanceId ).WaitWithContext (ctx )
333+ _ , err = wait .DeleteGitInstanceWaitHandler (ctx , g .client . DefaultAPI , projectId , instanceId ).WaitWithContext (ctx )
339334 if err != nil {
340335 core .LogAndAddError (ctx , & resp .Diagnostics , "Error waiting for instance deletion" , fmt .Sprintf ("Instance deletion waiting: %v" , err ))
341336 return
@@ -375,34 +370,30 @@ func mapFields(ctx context.Context, resp *git.Instance, model *Model) error {
375370 return fmt .Errorf ("model input is nil" )
376371 }
377372
378- if resp .Id == nil {
379- return fmt .Errorf ("git instance id not present" )
380- }
381-
382373 aclList := types .ListNull (types .StringType )
383374 var diags diag.Diagnostics
384- if resp . Acl != nil && len (* resp .Acl ) > 0 {
375+ if len (resp .Acl ) > 0 {
385376 aclList , diags = types .ListValueFrom (ctx , types .StringType , resp .Acl )
386377 if diags .HasError () {
387378 return fmt .Errorf ("mapping ACL: %w" , core .DiagsToError (diags ))
388379 }
389380 }
390381
391382 model .Created = types .StringNull ()
392- if resp .Created != nil && resp . Created .String () != "" {
383+ if resp .Created .String () != "" {
393384 model .Created = types .StringValue (resp .Created .String ())
394385 }
395386
396387 // Build the ID by combining the project ID and instance id and assign the model's fields.
397- model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), * resp .Id )
388+ model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), resp .Id )
398389 model .ACL = aclList
399- model .ConsumedDisk = types .StringPointerValue (resp .ConsumedDisk )
400- model .ConsumedObjectStorage = types .StringPointerValue (resp .ConsumedObjectStorage )
401- model .Flavor = types .StringPointerValue (resp .Flavor )
402- model .InstanceId = types .StringPointerValue (resp .Id )
403- model .Name = types .StringPointerValue (resp .Name )
404- model .Url = types .StringPointerValue (resp .Url )
405- model .Version = types .StringPointerValue (resp .Version )
390+ model .ConsumedDisk = types .StringValue (resp .ConsumedDisk )
391+ model .ConsumedObjectStorage = types .StringValue (resp .ConsumedObjectStorage )
392+ model .Flavor = types .StringValue (resp .Flavor )
393+ model .InstanceId = types .StringValue (resp .Id )
394+ model .Name = types .StringValue (resp .Name )
395+ model .Url = types .StringValue (resp .Url )
396+ model .Version = types .StringValue (resp .Version )
406397
407398 return nil
408399}
@@ -416,20 +407,20 @@ func toCreatePayload(ctx context.Context, model *Model) (git.CreateInstancePaylo
416407 }
417408
418409 payload := git.CreateInstancePayload {
419- Name : model .Name .ValueStringPointer (),
410+ Name : model .Name .ValueString (),
420411 }
421412
422413 if ! (model .ACL .IsNull () || model .ACL .IsUnknown ()) {
423414 var acl []string
424415 aclDiags := model .ACL .ElementsAs (ctx , & acl , false )
425416 diags .Append (aclDiags ... )
426417 if ! aclDiags .HasError () {
427- payload .Acl = & acl
418+ payload .Acl = acl
428419 }
429420 }
430421
431422 if ! (model .Flavor .IsNull () || model .Flavor .IsUnknown ()) {
432- payload .Flavor = git . CreateInstancePayloadGetFlavorAttributeType ( model .Flavor .ValueStringPointer () )
423+ payload .Flavor = model .Flavor .ValueStringPointer ()
433424 }
434425
435426 return payload , diags
0 commit comments