Skip to content

Commit 3bd0779

Browse files
committed
Handle 404 on deletes
1 parent 7c173e9 commit 3bd0779

16 files changed

+106
-5
lines changed

internal/provider/destination_filter_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ func (r *destinationFilterResource) Delete(ctx context.Context, req resource.Del
320320
defer body.Body.Close()
321321
}
322322
if err != nil {
323+
if body.StatusCode == http.StatusNotFound {
324+
resp.State.RemoveResource(ctx)
325+
326+
return
327+
}
328+
323329
resp.Diagnostics.AddError(
324330
fmt.Sprintf("Unable to delete Destination Filter (ID: %s)", state.ID.ValueString()),
325331
getError(err, body),

internal/provider/destination_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,12 @@ func (r *destinationResource) Delete(ctx context.Context, req resource.DeleteReq
701701
defer body.Body.Close()
702702
}
703703
if err != nil {
704+
if body.StatusCode == http.StatusNotFound {
705+
resp.State.RemoveResource(ctx)
706+
707+
return
708+
}
709+
704710
resp.Diagnostics.AddError(
705711
fmt.Sprintf("Unable to delete Destination (ID: %s)", state.ID.ValueString()),
706712
getError(err, body),

internal/provider/destination_subscription_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ func (r *destinationSubscriptionResource) Delete(ctx context.Context, req resour
359359
defer body.Body.Close()
360360
}
361361
if err != nil {
362+
if body.StatusCode == http.StatusNotFound {
363+
resp.State.RemoveResource(ctx)
364+
365+
return
366+
}
367+
362368
resp.Diagnostics.AddError(
363369
fmt.Sprintf("Unable to delete Destination subscription (ID: %s)", config.ID.ValueString()),
364370
getError(err, body),

internal/provider/function_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ func (r *functionResource) Delete(ctx context.Context, req resource.DeleteReques
290290
defer body.Body.Close()
291291
}
292292
if err != nil {
293+
if body.StatusCode == http.StatusNotFound || body.StatusCode == http.StatusForbidden {
294+
resp.State.RemoveResource(ctx)
295+
296+
return
297+
}
298+
293299
resp.Diagnostics.AddError(
294300
fmt.Sprintf("Unable to delete Function (ID: %s)", config.ID.ValueString()),
295301
getError(err, body),

internal/provider/insert_function_instance_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ func (r *insertFunctionInstanceResource) Delete(ctx context.Context, req resourc
277277
defer body.Body.Close()
278278
}
279279
if err != nil {
280+
if body.StatusCode == http.StatusNotFound {
281+
resp.State.RemoveResource(ctx)
282+
283+
return
284+
}
285+
280286
resp.Diagnostics.AddError(
281287
fmt.Sprintf("Unable to delete Insert Function instance (ID: %s)", config.ID.ValueString()),
282288
getError(err, body),

internal/provider/label_resource.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"context"
55
"fmt"
6+
"net/http"
67
"strings"
78

89
"github.com/hashicorp/terraform-plugin-framework/path"
@@ -200,6 +201,12 @@ func (r *labelResource) Delete(ctx context.Context, req resource.DeleteRequest,
200201
defer body.Body.Close()
201202
}
202203
if err != nil {
204+
if body.StatusCode == http.StatusNotFound {
205+
resp.State.RemoveResource(ctx)
206+
207+
return
208+
}
209+
203210
resp.Diagnostics.AddError(
204211
"Unable to delete Label",
205212
getError(err, body),

internal/provider/profiles_warehouse_resource.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"net/http"
78
"strings"
89

910
"github.com/segmentio/terraform-provider-segment/internal/provider/docs"
@@ -281,6 +282,12 @@ func (r *profilesWarehouseResource) Delete(ctx context.Context, req resource.Del
281282
defer body.Body.Close()
282283
}
283284
if err != nil {
285+
if body.StatusCode == http.StatusNotFound {
286+
resp.State.RemoveResource(ctx)
287+
288+
return
289+
}
290+
284291
resp.Diagnostics.AddError(
285292
fmt.Sprintf("Unable to delete Profiles Warehouse (ID: %s)", config.ID.ValueString()),
286293
getError(err, body),

internal/provider/reverse_etl_model_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ func (r *reverseETLModelResource) Delete(ctx context.Context, req resource.Delet
270270
defer body.Body.Close()
271271
}
272272
if err != nil {
273+
if body.StatusCode == http.StatusNotFound {
274+
resp.State.RemoveResource(ctx)
275+
276+
return
277+
}
278+
273279
resp.Diagnostics.AddError(
274280
fmt.Sprintf("Unable to delete Reverse ETL model (ID: %s)", config.ID.ValueString()),
275281
getError(err, body),

internal/provider/source_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ func (r *sourceResource) Delete(ctx context.Context, req resource.DeleteRequest,
552552
defer body.Body.Close()
553553
}
554554
if err != nil {
555+
if body.StatusCode == http.StatusNotFound {
556+
resp.State.RemoveResource(ctx)
557+
558+
return
559+
}
560+
555561
resp.Diagnostics.AddError(
556562
fmt.Sprintf("Unable to delete Source (ID: %s)", config.ID.ValueString()),
557563
getError(err, body),

internal/provider/source_tracking_plan_connection_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ func (r *sourceTrackingPlanConnectionResource) Delete(ctx context.Context, req r
408408
defer body.Body.Close()
409409
}
410410
if err != nil {
411+
if body.StatusCode == http.StatusNotFound {
412+
resp.State.RemoveResource(ctx)
413+
414+
return
415+
}
416+
411417
resp.Diagnostics.AddError(
412418
"Unable to remove Source-Tracking Plan connection",
413419
getError(err, body),

0 commit comments

Comments
 (0)