Skip to content

Commit 016a296

Browse files
committed
Handle missing resource on plan/apply
In Terrafor, we should continue if the resource is missing and just remove it from the state
1 parent 4d5e0eb commit 016a296

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal/provider/topic_resource.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,15 @@ func (r *topicResource) Read(ctx context.Context, req resource.ReadRequest, resp
184184

185185
topicInfo, err := r.client.GetTopic(ctx, data.ID.ValueString(), true)
186186
if err != nil {
187-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read topic, got error: %s", err))
188-
return
187+
switch err {
188+
case admin.ErrTopicDoesNotExist:
189+
// If the Topic does not exist, we remove it and return
190+
resp.State.RemoveResource(ctx)
191+
return
192+
default:
193+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read topic, got error: %s", err))
194+
return
195+
}
189196
}
190197

191198
replicationFactor, err := replicaCount(topicInfo)

0 commit comments

Comments
 (0)