@@ -31,7 +31,7 @@ const (
3131)
3232
3333type 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
0 commit comments