Skip to content

Commit

Permalink
Handle missing resource on plan/apply
Browse files Browse the repository at this point in the history
In Terrafor, we should continue if the resource is missing and just remove it from the state
  • Loading branch information
pecigonzalo committed Jan 10, 2023
1 parent 4d5e0eb commit 016a296
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/provider/topic_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 016a296

Please sign in to comment.