Skip to content

fix: Fix acceptance tests and Delete for stream_instance acceptance tests #3447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3447.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/mongodbatlas_stream_processor: Fixes Delete to wait until the resource is deleted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resource/mongodbatlas_stream_processor: Fixes Delete to wait until the resource is deleted
resource/mongodbatlas_stream_processor: Fixes Delete to wait until the resource is deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```
22 changes: 18 additions & 4 deletions internal/service/streamprocessor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package streamprocessor
import (
"context"
"errors"
"net/http"
"regexp"

"go.mongodb.org/atlas-sdk/v20250312004/admin"
Expand Down Expand Up @@ -247,17 +248,30 @@ func (r *streamProcessorRS) Update(ctx context.Context, req resource.UpdateReque
}

func (r *streamProcessorRS) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var streamProcessorState *TFStreamProcessorRSModel
resp.Diagnostics.Append(req.State.Get(ctx, &streamProcessorState)...)
var state TFStreamProcessorRSModel
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}

connV2 := r.Client.AtlasV2
if _, err := connV2.StreamsApi.DeleteStreamProcessor(ctx, streamProcessorState.ProjectID.ValueString(), streamProcessorState.InstanceName.ValueString(), streamProcessorState.ProcessorName.ValueString()).Execute(); err != nil {
params := &admin.GetStreamProcessorApiParams{
GroupId: state.ProjectID.ValueString(),
TenantName: state.InstanceName.ValueString(),
ProcessorName: state.ProcessorName.ValueString(),
}

if _, err := connV2.StreamsApi.DeleteStreamProcessor(ctx, params.GroupId, params.TenantName, params.ProcessorName).Execute(); err != nil {
resp.Diagnostics.AddError("error deleting resource", err.Error())
return
}
_, err := WaitStateTransition(ctx, params, connV2.StreamsApi, []string{InitiatingState, CreatingState, CreatedState, StartedState, StoppedState}, []string{DroppedState})
if apiError, _ := admin.AsError(err); apiError.GetError() == http.StatusBadRequest || apiError.GetError() == http.StatusNotFound {
return // resource already deleted
}
if err != nil {
resp.Diagnostics.AddError("error waiting for deleting resource", err.Error())
return
}
}

func (r *streamProcessorRS) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/streamprocessor/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func WaitStateTransition(ctx context.Context, requestParams *admin.GetStreamProc
Refresh: refreshFunc(ctx, requestParams, client),
Timeout: 5 * time.Minute, // big pipelines can take a while to stop due to checkpointing. We prefer the API to raise the error (~ 3min) than having to expose custom timeouts.
MinTimeout: 3 * time.Second,
Delay: 0,
Delay: 3 * time.Second,
}

streamProcessorResp, err := stateConf.WaitForStateContext(ctx)
Expand Down
Loading