Skip to content

Commit 0d91da8

Browse files
authored
Fix mis-read if a contact point exists in state but not in grafana (#645)
1 parent ccae862 commit 0d91da8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

grafana/resource_alerting_contact_point.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,15 @@ Manages Grafana Alerting contact points.
7373
func readContactPoint(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
7474
client := meta.(*client).gapi
7575

76-
uids := unpackUIDs(data.Id())
76+
uidsToFetch := unpackUIDs(data.Id())
7777

7878
points := []gapi.ContactPoint{}
79-
for _, uid := range uids {
79+
for _, uid := range uidsToFetch {
8080
p, err := client.ContactPoint(uid)
8181
if err != nil {
82-
if strings.HasPrefix(err.Error(), "status: 404") {
82+
if strings.HasPrefix(err.Error(), "status: 404") || strings.Contains(err.Error(), "not found") {
8383
log.Printf("[WARN] removing contact point %s from state because it no longer exists in grafana", uid)
84-
data.SetId("")
85-
return nil
84+
continue
8685
}
8786
return diag.FromErr(err)
8887
}
@@ -93,6 +92,10 @@ func readContactPoint(ctx context.Context, data *schema.ResourceData, meta inter
9392
if err != nil {
9493
return diag.FromErr(err)
9594
}
95+
uids := make([]string, 0, len(points))
96+
for _, p := range points {
97+
uids = append(uids, p.UID)
98+
}
9699
data.SetId(packUIDs(uids))
97100

98101
return nil

0 commit comments

Comments
 (0)