Skip to content

Commit 81f136e

Browse files
authored
fix(modelserving): store IDs immediately after provisioning (#1222)
relates to STACKITTPR-384
1 parent cbdee9f commit 81f136e

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • stackit/internal/services/modelserving/token

stackit/internal/services/modelserving/token/resource.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,23 @@ func (r *tokenResource) Create(ctx context.Context, req resource.CreateRequest,
302302

303303
ctx = core.LogResponse(ctx)
304304

305-
waitResp, err := wait.CreateModelServingWaitHandler(ctx, r.client, region, projectId, *createTokenResp.Token.Id).WaitWithContext(ctx)
305+
if createTokenResp.Token.Id == nil {
306+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating token", "Got empty token id")
307+
return
308+
}
309+
310+
tokenId := *createTokenResp.Token.Id
311+
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
312+
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
313+
"project_id": projectId,
314+
"region": region,
315+
"token_id": tokenId,
316+
})
317+
if resp.Diagnostics.HasError() {
318+
return
319+
}
320+
321+
waitResp, err := wait.CreateModelServingWaitHandler(ctx, r.client, region, projectId, tokenId).WaitWithContext(ctx)
306322
if err != nil {
307323
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating AI model serving auth token", fmt.Sprintf("Waiting for token to be active: %v", err))
308324
return

0 commit comments

Comments
 (0)