Skip to content

Commit 157e989

Browse files
committed
Handle 404s during reads
1 parent b412071 commit 157e989

16 files changed

+88
-8
lines changed

internal/provider/destination_filter_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ func (r *destinationFilterResource) Read(ctx context.Context, req resource.ReadR
201201
defer body.Body.Close()
202202
}
203203
if err != nil {
204+
if body.StatusCode == 404 {
205+
resp.State.RemoveResource(ctx)
206+
207+
return
208+
}
209+
204210
resp.Diagnostics.AddError(
205211
fmt.Sprintf("Unable to read Destination Filter (ID: %s)", previousState.ID.ValueString()),
206212
getError(err, body),

internal/provider/destination_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,12 @@ func (r *destinationResource) Read(ctx context.Context, req resource.ReadRequest
587587
defer body.Body.Close()
588588
}
589589
if err != nil {
590+
if body.StatusCode == 404 {
591+
resp.State.RemoveResource(ctx)
592+
593+
return
594+
}
595+
590596
resp.Diagnostics.AddError(
591597
fmt.Sprintf("Unable to read Destination (ID: %s)", previousState.ID.ValueString()),
592598
getError(err, body),

internal/provider/destination_subscription_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ func (r *destinationSubscriptionResource) Read(ctx context.Context, req resource
228228
defer body.Body.Close()
229229
}
230230
if err != nil {
231+
if body.StatusCode == 404 {
232+
resp.State.RemoveResource(ctx)
233+
234+
return
235+
}
236+
231237
resp.Diagnostics.AddError(
232238
fmt.Sprintf("Unable to read Destination subscription (ID: %s)", previousState.ID.ValueString()),
233239
getError(err, body),

internal/provider/function_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ func (r *functionResource) Read(ctx context.Context, req resource.ReadRequest, r
189189
defer body.Body.Close()
190190
}
191191
if err != nil {
192+
if body.StatusCode == 404 {
193+
resp.State.RemoveResource(ctx)
194+
195+
return
196+
}
197+
192198
resp.Diagnostics.AddError(
193199
fmt.Sprintf("Unable to read Function (ID: %s)", previousState.ID.ValueString()),
194200
getError(err, body),

internal/provider/insert_function_instance_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ func (r *insertFunctionInstanceResource) Read(ctx context.Context, req resource.
159159
defer body.Body.Close()
160160
}
161161
if err != nil {
162+
if body.StatusCode == 404 {
163+
resp.State.RemoveResource(ctx)
164+
165+
return
166+
}
167+
162168
resp.Diagnostics.AddError(
163169
fmt.Sprintf("Unable to read Insert Function instance (ID: %s)", previousState.ID.ValueString()),
164170
getError(err, body),

internal/provider/label_resource.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ func (r *labelResource) Read(ctx context.Context, req resource.ReadRequest, resp
163163
}
164164

165165
if label == nil {
166-
resp.Diagnostics.AddError(
167-
"Unable to find Label",
168-
fmt.Sprintf("Unable to find Label with key: %q and value: %q", state.Key, state.Value),
169-
)
166+
resp.State.RemoveResource(ctx)
170167

171168
return
172169
}

internal/provider/profiles_warehouse_resource.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ func (r *profilesWarehouseResource) Read(ctx context.Context, req resource.ReadR
167167

168168
warehouse, err := findProfileWarehouse(r.authContext, r.client, previousState.ID.ValueString(), previousState.SpaceID.ValueString())
169169
if err != nil {
170+
resp.State.RemoveResource(ctx)
171+
170172
resp.Diagnostics.AddError(
171173
fmt.Sprintf("Unable to read Profiles Warehouse (ID: %s)", previousState.ID.ValueString()),
172174
err.Error(),
@@ -176,10 +178,7 @@ func (r *profilesWarehouseResource) Read(ctx context.Context, req resource.ReadR
176178
}
177179

178180
if warehouse == nil {
179-
resp.Diagnostics.AddError(
180-
"Unable to find Profile Warehouse",
181-
fmt.Sprintf("Profile Warehouse with id '%s' and space id '%s' not found", previousState.ID.ValueString(), previousState.SpaceID.ValueString()),
182-
)
181+
resp.State.RemoveResource(ctx)
183182

184183
return
185184
}

internal/provider/reverse_etl_model_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ func (r *reverseETLModelResource) Read(ctx context.Context, req resource.ReadReq
160160
defer body.Body.Close()
161161
}
162162
if err != nil {
163+
if body.StatusCode == 404 {
164+
resp.State.RemoveResource(ctx)
165+
166+
return
167+
}
168+
163169
resp.Diagnostics.AddError(
164170
fmt.Sprintf("Unable to read Reverse ETL model (ID: %s)", previousState.ID.ValueString()),
165171
getError(err, body),

internal/provider/source_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ func (r *sourceResource) Read(ctx context.Context, req resource.ReadRequest, res
387387
defer body.Body.Close()
388388
}
389389
if err != nil {
390+
if body.StatusCode == 404 {
391+
resp.State.RemoveResource(ctx)
392+
393+
return
394+
}
395+
390396
resp.Diagnostics.AddError(
391397
fmt.Sprintf("Unable to read Source (ID: %s)", previousState.ID.ValueString()),
392398
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
@@ -255,6 +255,12 @@ func (r *sourceTrackingPlanConnectionResource) Read(ctx context.Context, req res
255255
defer body.Body.Close()
256256
}
257257
if err != nil {
258+
if body.StatusCode == 404 {
259+
resp.State.RemoveResource(ctx)
260+
261+
return
262+
}
263+
258264
resp.Diagnostics.AddError(
259265
fmt.Sprintf("Unable to read Source (ID: %s)", previousState.SourceID.ValueString()),
260266
getError(err, body),

0 commit comments

Comments
 (0)