@@ -12,6 +12,7 @@ import (
1212 "github.com/hashicorp/terraform-plugin-framework/diag"
1313 "github.com/hashicorp/terraform-plugin-framework/resource"
1414 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
15+ "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/cleanup"
1516 "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy"
1617 "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate"
1718 "github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
@@ -44,6 +45,7 @@ type HandleCreateReq struct {
4445 Client * config.MongoDBClient
4546 Plan any
4647 CallParams * config.APICallParams
48+ DeleteCallParams * config.APICallParams
4749 Wait * WaitReq
4850 DeleteOnCreateTimeout bool
4951}
@@ -70,8 +72,19 @@ func HandleCreate(ctx context.Context, req HandleCreateReq) {
7072 addError (d , opCreate , errResolvingResponse , err )
7173 return
7274 }
73- if err := handleWaitCreateUpdate (ctx , req .Wait , req .Client , req .Plan ); err != nil {
74- addError (d , opCreate , errWaitingForChanges , err )
75+ errWait := handleWaitCreateUpdate (ctx , req .Wait , req .Client , req .Plan )
76+ if errWait != nil && req .Wait != nil && req .DeleteCallParams != nil {
77+ // Handle timeout with cleanup if delete_on_create_timeout is enabled. Doesn't support Delete with StaticRequestBody.
78+ errWait = cleanup .HandleCreateTimeout (req .DeleteOnCreateTimeout , errWait , func (ctxCleanup context.Context ) error {
79+ bodyResp , apiResp , err := callAPIWithoutBody (ctxCleanup , req .Client , req .DeleteCallParams )
80+ if notFound (bodyResp , apiResp ) {
81+ return nil
82+ }
83+ return err
84+ })
85+ }
86+ if errWait != nil {
87+ addError (d , opCreate , errWaitingForChanges , errWait )
7588 return
7689 }
7790 req .Resp .Diagnostics .Append (req .Resp .State .Set (ctx , req .Plan )... )
0 commit comments