Clears branch protection from state only if error is an HTTP 404 (#13887)

This commit is contained in:
Andy Lindeman 2017-04-24 13:19:27 -04:00 committed by Paul Stack
parent fe15c68aa9
commit 46fd77bbed

View File

@ -3,6 +3,7 @@ package github
import ( import (
"context" "context"
"errors" "errors"
"net/http"
"github.com/google/go-github/github" "github.com/google/go-github/github"
"github.com/hashicorp/terraform/helper/schema" "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) githubProtection, _, err := client.Repositories.GetBranchProtection(context.TODO(), meta.(*Organization).name, r, b)
if err != nil { if err != nil {
d.SetId("") if err, ok := err.(*github.ErrorResponse); ok && err.Response.StatusCode == http.StatusNotFound {
return nil d.SetId("")
return nil
}
return err
} }
d.Set("repository", r) d.Set("repository", r)