From 016a2963ef8595a44c82545a33a9463a99f30e93 Mon Sep 17 00:00:00 2001 From: Gonzalo Peci Date: Tue, 10 Jan 2023 09:06:17 -0300 Subject: [PATCH] Handle missing resource on plan/apply In Terrafor, we should continue if the resource is missing and just remove it from the state --- internal/provider/topic_resource.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/provider/topic_resource.go b/internal/provider/topic_resource.go index 8dda448..385d848 100644 --- a/internal/provider/topic_resource.go +++ b/internal/provider/topic_resource.go @@ -184,8 +184,15 @@ func (r *topicResource) Read(ctx context.Context, req resource.ReadRequest, resp topicInfo, err := r.client.GetTopic(ctx, data.ID.ValueString(), true) if err != nil { - resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read topic, got error: %s", err)) - return + switch err { + case admin.ErrTopicDoesNotExist: + // If the Topic does not exist, we remove it and return + resp.State.RemoveResource(ctx) + return + default: + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read topic, got error: %s", err)) + return + } } replicationFactor, err := replicaCount(topicInfo)