fix: pgsql user waiter
This commit is contained in:
parent
847bc0d3c2
commit
f2c9af8fc5
2 changed files with 31 additions and 9 deletions
|
|
@ -220,13 +220,13 @@ func (r *userResource) Create(
|
||||||
model.Status = types.StringValue(userResp.GetStatus())
|
model.Status = types.StringValue(userResp.GetStatus())
|
||||||
model.ConnectionString = types.StringValue(userResp.GetConnectionString())
|
model.ConnectionString = types.StringValue(userResp.GetConnectionString())
|
||||||
|
|
||||||
waitResp, err := postgresflexalphaWait.CreateUserWaitHandler(
|
waitResp, err := postgresflexalphaWait.GetUserByIdWaitHandler(
|
||||||
ctx,
|
ctx,
|
||||||
r.client,
|
r.client,
|
||||||
arg.projectId,
|
arg.projectId,
|
||||||
arg.instanceId,
|
arg.instanceId,
|
||||||
arg.region,
|
arg.region,
|
||||||
arg.userId,
|
id,
|
||||||
).SetSleepBeforeWait(
|
).SetSleepBeforeWait(
|
||||||
10 * time.Second,
|
10 * time.Second,
|
||||||
).SetTimeout(
|
).SetTimeout(
|
||||||
|
|
@ -243,7 +243,7 @@ func (r *userResource) Create(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if waitResp.Id == nil || *waitResp.Id != arg.userId {
|
if waitResp.Id == nil || *waitResp.Id != id {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
&resp.Diagnostics,
|
&resp.Diagnostics,
|
||||||
|
|
@ -288,17 +288,39 @@ func (r *userResource) Read(
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
// Read resource state
|
// 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 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if waitResp.Id == nil || *waitResp.Id != arg.userId {
|
||||||
resp.State.RemoveResource(ctx)
|
core.LogAndAddError(
|
||||||
|
ctx,
|
||||||
|
&resp.Diagnostics,
|
||||||
|
"read user",
|
||||||
|
"Instance creation waiting: returned id is nil or wrong",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
arg.userId = *waitResp.Id
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,8 +206,8 @@ func PartialUpdateInstanceWaitHandler(
|
||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateUserWaitHandler will wait for instance creation
|
// GetUserByIdWaitHandler will wait for instance creation
|
||||||
func CreateUserWaitHandler(
|
func GetUserByIdWaitHandler(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
a APIClientUserInterface,
|
a APIClientUserInterface,
|
||||||
projectId, instanceId, region string,
|
projectId, instanceId, region string,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue