@@ -21,8 +21,8 @@ import (
2121 "github.com/hashicorp/terraform-plugin-framework/types"
2222 "github.com/hashicorp/terraform-plugin-log/tflog"
2323 "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
24- "github.com/stackitcloud/stackit-sdk-go/services/modelserving"
25- "github.com/stackitcloud/stackit-sdk-go/services/modelserving/wait"
24+ modelserving "github.com/stackitcloud/stackit-sdk-go/services/modelserving/v1api "
25+ "github.com/stackitcloud/stackit-sdk-go/services/modelserving/v1api/ wait"
2626 "github.com/stackitcloud/stackit-sdk-go/services/serviceenablement"
2727 serviceEnablementWait "github.com/stackitcloud/stackit-sdk-go/services/serviceenablement/wait"
2828
@@ -288,7 +288,7 @@ func (r *tokenResource) Create(ctx context.Context, req resource.CreateRequest,
288288 }
289289
290290 // Create new AI model serving auth token
291- createTokenResp , err := r .client .CreateToken (ctx , region , projectId ).
291+ createTokenResp , err := r .client .DefaultAPI . CreateToken (ctx , region , projectId ).
292292 CreateTokenPayload (* payload ).
293293 Execute ()
294294 if err != nil {
@@ -303,12 +303,12 @@ func (r *tokenResource) Create(ctx context.Context, req resource.CreateRequest,
303303
304304 ctx = core .LogResponse (ctx )
305305
306- if createTokenResp .Token .Id == nil {
306+ if createTokenResp .Token .Id == "" {
307307 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating token" , "Got empty token id" )
308308 return
309309 }
310310
311- tokenId := * createTokenResp .Token .Id
311+ tokenId := createTokenResp .Token .Id
312312 // Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
313313 ctx = utils .SetAndLogStateFields (ctx , & resp .Diagnostics , & resp .State , map [string ]any {
314314 "project_id" : projectId ,
@@ -319,7 +319,7 @@ func (r *tokenResource) Create(ctx context.Context, req resource.CreateRequest,
319319 return
320320 }
321321
322- waitResp , err := wait .CreateModelServingWaitHandler (ctx , r .client , region , projectId , tokenId ).WaitWithContext (ctx )
322+ waitResp , err := wait .CreateModelServingWaitHandler (ctx , r .client . DefaultAPI , region , projectId , tokenId ).WaitWithContext (ctx )
323323 if err != nil {
324324 core .LogAndAddError (ctx , & resp .Diagnostics , "Error creating AI model serving auth token" , fmt .Sprintf ("Waiting for token to be active: %v" , err ))
325325 return
@@ -361,7 +361,7 @@ func (r *tokenResource) Read(ctx context.Context, req resource.ReadRequest, resp
361361 ctx = tflog .SetField (ctx , "token_id" , tokenId )
362362 ctx = tflog .SetField (ctx , "region" , region )
363363
364- getTokenResp , err := r .client .GetToken (ctx , region , projectId , tokenId ).
364+ getTokenResp , err := r .client .DefaultAPI . GetToken (ctx , region , projectId , tokenId ).
365365 Execute ()
366366 if err != nil {
367367 var oapiErr * oapierror.GenericOpenAPIError
@@ -379,8 +379,7 @@ func (r *tokenResource) Read(ctx context.Context, req resource.ReadRequest, resp
379379
380380 ctx = core .LogResponse (ctx )
381381
382- if getTokenResp != nil && getTokenResp .Token .State != nil &&
383- * getTokenResp .Token .State == inactiveState {
382+ if getTokenResp != nil && getTokenResp .Token .State == inactiveState {
384383 resp .State .RemoveResource (ctx )
385384 core .LogAndAddWarning (ctx , & resp .Diagnostics , "Error reading AI model serving auth token" , "AI model serving auth token has expired" )
386385 return
@@ -440,7 +439,7 @@ func (r *tokenResource) Update(ctx context.Context, req resource.UpdateRequest,
440439 }
441440
442441 // Update AI model serving auth token
443- updateTokenResp , err := r .client .PartialUpdateToken (ctx , region , projectId , tokenId ).PartialUpdateTokenPayload (* payload ).Execute ()
442+ updateTokenResp , err := r .client .DefaultAPI . PartialUpdateToken (ctx , region , projectId , tokenId ).PartialUpdateTokenPayload (* payload ).Execute ()
444443 if err != nil {
445444 var oapiErr * oapierror.GenericOpenAPIError
446445 if errors .As (err , & oapiErr ) {
@@ -468,14 +467,13 @@ func (r *tokenResource) Update(ctx context.Context, req resource.UpdateRequest,
468467
469468 ctx = core .LogResponse (ctx )
470469
471- if updateTokenResp != nil && updateTokenResp .Token .State != nil &&
472- * updateTokenResp .Token .State == inactiveState {
470+ if updateTokenResp != nil && updateTokenResp .Token .State == inactiveState {
473471 resp .State .RemoveResource (ctx )
474472 core .LogAndAddWarning (ctx , & resp .Diagnostics , "Error updating AI model serving auth token" , "AI model serving auth token has expired" )
475473 return
476474 }
477475
478- waitResp , err := wait .UpdateModelServingWaitHandler (ctx , r .client , region , projectId , tokenId ).WaitWithContext (ctx )
476+ waitResp , err := wait .UpdateModelServingWaitHandler (ctx , r .client . DefaultAPI , region , projectId , tokenId ).WaitWithContext (ctx )
479477 if err != nil {
480478 core .LogAndAddError (ctx , & resp .Diagnostics , "Error updating AI model serving auth token" , fmt .Sprintf ("Waiting for token to be updated: %v" , err ))
481479 return
@@ -520,7 +518,7 @@ func (r *tokenResource) Delete(ctx context.Context, req resource.DeleteRequest,
520518 ctx = tflog .SetField (ctx , "region" , region )
521519
522520 // Delete existing AI model serving auth token. We will ignore the state 'deleting' for now.
523- _ , err := r .client .DeleteToken (ctx , region , projectId , tokenId ).Execute ()
521+ _ , err := r .client .DefaultAPI . DeleteToken (ctx , region , projectId , tokenId ).Execute ()
524522 if err != nil {
525523 var oapiErr * oapierror.GenericOpenAPIError
526524 if errors .As (err , & oapiErr ) {
@@ -536,7 +534,7 @@ func (r *tokenResource) Delete(ctx context.Context, req resource.DeleteRequest,
536534
537535 ctx = core .LogResponse (ctx )
538536
539- _ , err = wait .DeleteModelServingWaitHandler (ctx , r .client , region , projectId , tokenId ).
537+ _ , err = wait .DeleteModelServingWaitHandler (ctx , r .client . DefaultAPI , region , projectId , tokenId ).
540538 WaitWithContext (ctx )
541539 if err != nil {
542540 core .LogAndAddError (ctx , & resp .Diagnostics , "Error deleting AI model serving auth token" , fmt .Sprintf ("Waiting for token to be deleted: %v" , err ))
@@ -547,7 +545,7 @@ func (r *tokenResource) Delete(ctx context.Context, req resource.DeleteRequest,
547545}
548546
549547func mapCreateResponse (tokenCreateResp * modelserving.CreateTokenResponse , waitResp * modelserving.GetTokenResponse , model * Model , region string ) error {
550- if tokenCreateResp == nil || tokenCreateResp . Token == nil {
548+ if tokenCreateResp == nil {
551549 return fmt .Errorf ("response input is nil" )
552550 }
553551 if model == nil {
@@ -556,25 +554,25 @@ func mapCreateResponse(tokenCreateResp *modelserving.CreateTokenResponse, waitRe
556554
557555 token := tokenCreateResp .Token
558556
559- if token .Id == nil {
557+ if token .Id == "" {
560558 return fmt .Errorf ("token id not present" )
561559 }
562560
563561 validUntil := types .StringNull ()
564- if token .ValidUntil != nil {
562+ if ! token .ValidUntil . IsZero () {
565563 validUntil = types .StringValue (token .ValidUntil .Format (time .RFC3339 ))
566564 }
567565
568- if waitResp == nil || waitResp . Token == nil || waitResp . Token . State == nil {
566+ if waitResp == nil {
569567 return fmt .Errorf ("response input is nil" )
570568 }
571569
572- model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), region , * tokenCreateResp .Token .Id )
573- model .TokenId = types .StringPointerValue (token .Id )
574- model .Name = types .StringPointerValue (token .Name )
575- model .State = types .StringValue (string ( waitResp .Token .GetState ()) )
570+ model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), region , tokenCreateResp .Token .Id )
571+ model .TokenId = types .StringValue (token .Id )
572+ model .Name = types .StringValue (token .Name )
573+ model .State = types .StringValue (waitResp .Token .State )
576574 model .ValidUntil = validUntil
577- model .Token = types .StringPointerValue (token .Content )
575+ model .Token = types .StringValue (token .Content )
578576 model .Description = types .StringPointerValue (token .Description )
579577
580578 return nil
@@ -585,23 +583,20 @@ func mapGetResponse(tokenGetResp *modelserving.GetTokenResponse, model *Model) e
585583 return fmt .Errorf ("response input is nil" )
586584 }
587585
588- if tokenGetResp .Token == nil {
589- return fmt .Errorf ("response input is nil" )
590- }
591586 if model == nil {
592587 return fmt .Errorf ("model input is nil" )
593588 }
594589
595- // theoretically, should never happen, but still catch null pointers
590+ // theoretically, should never happen, but still catch zero values
596591 validUntil := types .StringNull ()
597- if tokenGetResp .Token .ValidUntil != nil {
592+ if ! tokenGetResp .Token .ValidUntil . IsZero () {
598593 validUntil = types .StringValue (tokenGetResp .Token .ValidUntil .Format (time .RFC3339 ))
599594 }
600595
601596 model .Id = utils .BuildInternalTerraformId (model .ProjectId .ValueString (), model .Region .ValueString (), model .TokenId .ValueString ())
602- model .TokenId = types .StringPointerValue (tokenGetResp .Token .Id )
603- model .Name = types .StringPointerValue (tokenGetResp .Token .Name )
604- model .State = types .StringValue (string ( tokenGetResp .Token .GetState ()) )
597+ model .TokenId = types .StringValue (tokenGetResp .Token .Id )
598+ model .Name = types .StringValue (tokenGetResp .Token .Name )
599+ model .State = types .StringValue (tokenGetResp .Token .State )
605600 model .ValidUntil = validUntil
606601 model .Description = types .StringPointerValue (tokenGetResp .Token .Description )
607602
@@ -614,7 +609,7 @@ func toCreatePayload(model *Model) (*modelserving.CreateTokenPayload, error) {
614609 }
615610
616611 return & modelserving.CreateTokenPayload {
617- Name : conversion . StringValueToPointer ( model .Name ),
612+ Name : model .Name . ValueString ( ),
618613 Description : conversion .StringValueToPointer (model .Description ),
619614 TtlDuration : conversion .StringValueToPointer (model .TTLDuration ),
620615 }, nil
0 commit comments