Skip to content

Commit

Permalink
fix: On read, unset ID when resource not found (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwholey authored Nov 4, 2021
1 parent 003e7bc commit 715e87c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/provider/resource_cname_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func resourceCNAMERecordRead(ctx context.Context, d *schema.ResourceData, meta i

record, err := client.GetCNAMERecord(ctx, d.Id())
if err != nil {
if _, ok := err.(*pihole.NotFoundError); ok {
d.SetId("")
return nil
}

return diag.FromErr(err)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/provider/resource_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func resourceDNSRecordRead(ctx context.Context, d *schema.ResourceData, meta int

record, err := client.GetDNSRecord(ctx, d.Id())
if err != nil {
if _, ok := err.(*pihole.NotFoundError); ok {
d.SetId("")
return nil
}

return diag.FromErr(err)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/provider/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func resourceGroupRead(ctx context.Context, d *schema.ResourceData, meta interfa

group, err := client.GetGroup(ctx, name)
if err != nil {
if _, ok := err.(*pihole.NotFoundError); ok {
d.SetId("")
return nil
}

return diag.FromErr(err)
}

Expand Down

0 comments on commit 715e87c

Please sign in to comment.