fix: pgsql user waiter

This commit is contained in:
Marcel S. Henselin 2026-02-13 08:31:25 +01:00
parent 847bc0d3c2
commit f2c9af8fc5
2 changed files with 31 additions and 9 deletions

View file

@ -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)

View file

@ -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,