Skip to content

Commit

Permalink
fix(resource_github_release): Handle missing release in read (#2115)
Browse files Browse the repository at this point in the history
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
arunsathiya and kfcampbell committed Feb 5, 2024
1 parent 970dd20 commit 9008816
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions github/resource_github_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/http"
"strconv"

"github.com/google/go-github/v57/github"
Expand Down Expand Up @@ -162,6 +163,13 @@ func resourceGithubReleaseRead(d *schema.ResourceData, meta interface{}) error {

release, _, err := client.Repositories.GetRelease(ctx, owner, repository, releaseID)
if err != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotFound {
log.Printf("[INFO] Removing release ID %d for repository %s from state, because it no longer exists on GitHub", releaseID, repository)
d.SetId("")
return nil
}
}
return err
}
transformResponseToResourceData(d, release, repository)
Expand Down

0 comments on commit 9008816

Please sign in to comment.