mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-07 14:44:11 -06:00
Clears branch protection from state only if error is an HTTP 404 (#13887)
This commit is contained in:
parent
fe15c68aa9
commit
46fd77bbed
@ -3,6 +3,7 @@ package github
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
@ -117,8 +118,12 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta interface{}
|
||||
|
||||
githubProtection, _, err := client.Repositories.GetBranchProtection(context.TODO(), meta.(*Organization).name, r, b)
|
||||
if err != nil {
|
||||
d.SetId("")
|
||||
return nil
|
||||
if err, ok := err.(*github.ErrorResponse); ok && err.Response.StatusCode == http.StatusNotFound {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
d.Set("repository", r)
|
||||
|
Loading…
Reference in New Issue
Block a user