From 46fd77bbed442ecf78d593f8306bb2582960a49a Mon Sep 17 00:00:00 2001 From: Andy Lindeman Date: Mon, 24 Apr 2017 13:19:27 -0400 Subject: [PATCH] Clears branch protection from state only if error is an HTTP 404 (#13887) --- .../github/resource_github_branch_protection.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/builtin/providers/github/resource_github_branch_protection.go b/builtin/providers/github/resource_github_branch_protection.go index bb9f5ba2d0..2032835768 100644 --- a/builtin/providers/github/resource_github_branch_protection.go +++ b/builtin/providers/github/resource_github_branch_protection.go @@ -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)