From f2c9af8fc5aced2a996e3b1294b5b3a76741fc30 Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Fri, 13 Feb 2026 08:31:25 +0100 Subject: [PATCH] fix: pgsql user waiter --- .../postgresflexalpha/user/resource.go | 36 +++++++++++++++---- .../internal/wait/postgresflexalpha/wait.go | 4 +-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/stackit/internal/services/postgresflexalpha/user/resource.go b/stackit/internal/services/postgresflexalpha/user/resource.go index 7498bdb1..5be7f650 100644 --- a/stackit/internal/services/postgresflexalpha/user/resource.go +++ b/stackit/internal/services/postgresflexalpha/user/resource.go @@ -220,13 +220,13 @@ func (r *userResource) Create( model.Status = types.StringValue(userResp.GetStatus()) model.ConnectionString = types.StringValue(userResp.GetConnectionString()) - waitResp, err := postgresflexalphaWait.CreateUserWaitHandler( + waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler( ctx, r.client, arg.projectId, arg.instanceId, arg.region, - arg.userId, + id, ).SetSleepBeforeWait( 10 * time.Second, ).SetTimeout( @@ -243,7 +243,7 @@ func (r *userResource) Create( return } - if waitResp.Id == nil || *waitResp.Id != arg.userId { + if waitResp.Id == nil || *waitResp.Id != id { core.LogAndAddError( ctx, &resp.Diagnostics, @@ -288,17 +288,39 @@ func (r *userResource) Read( ctx = core.InitProviderContext(ctx) // Read resource state - exists, err := r.getUserResource(ctx, &model, arg) + waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler( + ctx, + r.client, + arg.projectId, + arg.instanceId, + arg.region, + model.UserId.ValueInt64(), + ).SetSleepBeforeWait( + 10 * time.Second, + ).SetTimeout( + 15 * time.Minute, + ).WaitWithContext(ctx) if err != nil { - core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading user", fmt.Sprintf("Calling API: %v", err)) + core.LogAndAddError( + ctx, + &resp.Diagnostics, + "read user", + fmt.Sprintf("Instance creation waiting: %v", err), + ) return } - if !exists { - resp.State.RemoveResource(ctx) + if waitResp.Id == nil || *waitResp.Id != arg.userId { + core.LogAndAddError( + ctx, + &resp.Diagnostics, + "read user", + "Instance creation waiting: returned id is nil or wrong", + ) return } + arg.userId = *waitResp.Id ctx = core.LogResponse(ctx) diff --git a/stackit/internal/wait/postgresflexalpha/wait.go b/stackit/internal/wait/postgresflexalpha/wait.go index 8f82dfbb..505fc0a1 100644 --- a/stackit/internal/wait/postgresflexalpha/wait.go +++ b/stackit/internal/wait/postgresflexalpha/wait.go @@ -206,8 +206,8 @@ func PartialUpdateInstanceWaitHandler( return handler } -// CreateUserWaitHandler will wait for instance creation -func CreateUserWaitHandler( +// GetUserByIdWaitHandler will wait for instance creation +func GetUserByIdWaitHandler( ctx context.Context, a APIClientUserInterface, projectId, instanceId, region string,