Skip to content

Commit 1be1ac3

Browse files
authored
chore: Support LRO value from response in autogen resources (#3829)
1 parent acffdf8 commit 1be1ac3

File tree

31 files changed

+2183
-135
lines changed

31 files changed

+2183
-135
lines changed

.github/workflows/acceptance-tests-runner.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ jobs:
312312
- 'internal/serviceapi/clusterapi/*.go'
313313
- 'internal/serviceapi/pushbasedlogexportapi/*.go'
314314
- 'internal/serviceapi/searchdeploymentapi/*.go'
315+
- 'internal/serviceapi/searchindexapi/*.go'
315316
- 'internal/serviceapi/streaminstanceapi/*.go'
316317
- 'internal/serviceapi/streamprocessorapi/*.go'
317318
backup:
@@ -682,6 +683,7 @@ jobs:
682683
./internal/serviceapi/clusterapi
683684
./internal/serviceapi/pushbasedlogexportapi
684685
./internal/serviceapi/searchdeploymentapi
686+
./internal/serviceapi/searchindexapi
685687
./internal/serviceapi/streaminstanceapi
686688
./internal/serviceapi/streamprocessorapi
687689
run: make testacc

internal/common/autogen/handle_operations.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
)
3232

3333
type WaitReq struct {
34-
CallParams *config.APICallParams
34+
CallParams func(model any) *config.APICallParams
3535
StateProperty string
3636
PendingStates []string
3737
TargetStates []string
@@ -45,7 +45,7 @@ type HandleCreateReq struct {
4545
Client *config.MongoDBClient
4646
Plan any
4747
CallParams *config.APICallParams
48-
DeleteReq *HandleDeleteReq
48+
DeleteReq func(model any) *HandleDeleteReq
4949
Wait *WaitReq
5050
DeleteOnCreateTimeout bool
5151
}
@@ -76,7 +76,8 @@ func HandleCreate(ctx context.Context, req HandleCreateReq) {
7676
if req.DeleteReq != nil {
7777
// Handle timeout with cleanup if delete_on_create_timeout is enabled.
7878
errWait = cleanup.HandleCreateTimeout(req.DeleteOnCreateTimeout, errWait, func(ctxCleanup context.Context) error {
79-
return callDelete(ctxCleanup, req.DeleteReq)
79+
deleteReq := req.DeleteReq(req.Plan)
80+
return callDelete(ctxCleanup, deleteReq)
8081
})
8182
}
8283
if errWait != nil {
@@ -168,7 +169,7 @@ func HandleDelete(ctx context.Context, req HandleDeleteReq) {
168169
addError(req.Diags, opDelete, errCallingAPI, err)
169170
return
170171
}
171-
if errWait := handleWaitDelete(ctx, req.Wait, req.Client); errWait != nil {
172+
if errWait := handleWaitDelete(ctx, req.Wait, req.Client, req.State); errWait != nil {
172173
addError(req.Diags, opDelete, errWaitingForChanges, errWait)
173174
}
174175
}
@@ -179,7 +180,7 @@ func handleWaitCreateUpdate(ctx context.Context, wait *WaitReq, client *config.M
179180
if wait == nil {
180181
return nil
181182
}
182-
bodyResp, err := waitForChanges(ctx, wait, client)
183+
bodyResp, err := waitForChanges(ctx, wait, client, model)
183184
if err != nil || isEmptyJSON(bodyResp) {
184185
return err
185186
}
@@ -190,11 +191,11 @@ func handleWaitCreateUpdate(ctx context.Context, wait *WaitReq, client *config.M
190191
}
191192

192193
// handleWaitDelete waits until a long-running operation to delete a resource if neeed.
193-
func handleWaitDelete(ctx context.Context, wait *WaitReq, client *config.MongoDBClient) error {
194+
func handleWaitDelete(ctx context.Context, wait *WaitReq, client *config.MongoDBClient, model any) error {
194195
if wait == nil {
195196
return nil
196197
}
197-
if _, err := waitForChanges(ctx, wait, client); err != nil {
198+
if _, err := waitForChanges(ctx, wait, client, model); err != nil {
198199
return err
199200
}
200201
return nil
@@ -253,7 +254,7 @@ func callDelete(ctx context.Context, req *HandleDeleteReq) error {
253254

254255
// waitForChanges waits until a long-running operation is done.
255256
// It returns the latest JSON response from the API so it can be used to update the response state.
256-
func waitForChanges(ctx context.Context, wait *WaitReq, client *config.MongoDBClient) ([]byte, error) {
257+
func waitForChanges(ctx context.Context, wait *WaitReq, client *config.MongoDBClient, model any) ([]byte, error) {
257258
if len(wait.TargetStates) == 0 {
258259
return nil, fmt.Errorf("wait must have at least one target state, pending states: %v", wait.PendingStates)
259260
}
@@ -263,7 +264,7 @@ func waitForChanges(ctx context.Context, wait *WaitReq, client *config.MongoDBCl
263264
Timeout: wait.Timeout,
264265
MinTimeout: time.Duration(wait.MinTimeoutSeconds) * time.Second,
265266
Delay: time.Duration(wait.DelaySeconds) * time.Second,
266-
Refresh: refreshFunc(ctx, wait, client),
267+
Refresh: refreshFunc(ctx, wait, client, model),
267268
}
268269
bodyResp, err := stateConf.WaitForStateContext(ctx)
269270
if err != nil || bodyResp == nil {
@@ -274,9 +275,10 @@ func waitForChanges(ctx context.Context, wait *WaitReq, client *config.MongoDBCl
274275

275276
// refreshFunc retries until a target state or error happens.
276277
// It uses a special state value of "DELETED" when the API returns 404 or empty object
277-
func refreshFunc(ctx context.Context, wait *WaitReq, client *config.MongoDBClient) retry.StateRefreshFunc {
278+
func refreshFunc(ctx context.Context, wait *WaitReq, client *config.MongoDBClient, model any) retry.StateRefreshFunc {
278279
return func() (result any, state string, err error) {
279-
bodyResp, httpResp, err := callAPIWithoutBody(ctx, client, wait.CallParams)
280+
callParams := wait.CallParams(model)
281+
bodyResp, httpResp, err := callAPIWithoutBody(ctx, client, callParams)
280282
if notFound(bodyResp, httpResp) {
281283
// if "artificial" states continue to grow we can evaluate using a prefix to clearly separate states coming from API and those defined by refreshFunc
282284
return emptyJSON, retrystrategy.RetryStrategyDeletedState, nil

internal/serviceapi/auditingapi/resource.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/clusterapi/resource.go

Lines changed: 14 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/customdbroleapi/resource.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/databaseuserapi/resource.go

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/maintenancewindowapi/resource.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/orgserviceaccountapi/resource.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/projectapi/resource.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/projectsettingsapi/resource.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)