Skip to content

Commit

Permalink
Merge pull request #108 from wlynch/read-delete
Browse files Browse the repository at this point in the history
ko_build.Read: Check if underlying directory has been deleted.
  • Loading branch information
imjasonh authored Nov 29, 2023
2 parents b7defef + 92c7854 commit fd2666f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/provider/resource_ko_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func resourceKoBuildCreate(ctx context.Context, d *schema.ResourceData, meta int

ref, err := doBuild(ctx, fromData(d, po))
if err != nil {
return diag.Errorf("doBuild: %v", err)
return diag.Errorf("[id=%s] create doBuild: %v", d.Id(), err)
}

_ = d.Set("image_ref", ref)
Expand All @@ -301,7 +301,14 @@ func resourceKoBuildRead(ctx context.Context, d *schema.ResourceData, meta inter

ref, err := doBuild(ctx, fromData(d, po))
if err != nil {
return diag.Errorf("doBuild: %v", err)
// Check for conditions that might indicate that the underlying module has been deleted.
// This is not an exhaustive list, but is a best effort check to see if the build failed because a deletion.
// See https://www.hashicorp.com/blog/writing-custom-terraform-providers#implementing-read for more details.
if errors.Is(err, os.ErrNotExist) {
d.SetId("")
return nil
}
return diag.Errorf("[id=%s] read doBuild: %v", d.Id(), err)
}

_ = d.Set("image_ref", ref)
Expand Down

0 comments on commit fd2666f

Please sign in to comment.