Skip to content

Commit 88d049e

Browse files
committed
Handle state refresh for gnmi resource
1 parent 96b2c60 commit 88d049e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

internal/provider/resource_iosxr_gnmi.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package provider
2020
import (
2121
"context"
2222
"fmt"
23+
"strings"
2324

2425
"github.com/CiscoDevNet/terraform-provider-iosxr/internal/provider/client"
2526
"github.com/hashicorp/terraform-plugin-framework/path"
@@ -192,8 +193,13 @@ func (r *GnmiResource) Read(ctx context.Context, req resource.ReadRequest, resp
192193

193194
getResp, err := r.client.Get(ctx, state.Device.ValueString(), state.Path.ValueString())
194195
if err != nil {
195-
resp.Diagnostics.AddError("Unable to apply gNMI Get operation", err.Error())
196-
return
196+
if strings.Contains(err.Error(), "Requested element(s) not found") {
197+
resp.State.RemoveResource(ctx)
198+
return
199+
} else {
200+
resp.Diagnostics.AddError("Unable to apply gNMI Get operation", err.Error())
201+
return
202+
}
197203
}
198204

199205
diags = state.fromBody(ctx, getResp.Notification[0].Update[0].Val.GetJsonIetfVal())

0 commit comments

Comments
 (0)