diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 9540f83eff..2419dee190 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -634,9 +634,10 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository { } // only configure allow forking if repository is not public - allowForking, ok := d.Get("allow_forking").(bool) - if ok && visibility != "public" { - repository.AllowForking = github.Ptr(allowForking) + if allowForking, ok := d.GetOk("allow_forking"); ok && visibility != "public" { + if val, ok := allowForking.(bool); ok { + repository.AllowForking = github.Ptr(val) + } } return repository diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 9bfde4fd9a..b83f0c7c62 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -571,7 +571,7 @@ func TestAccGithubRepository(t *testing.T) { t.Run("create_private_with_forking", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) - repoName := fmt.Sprintf("%svisibility-%s", testResourcePrefix, randomID) + repoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID) config := fmt.Sprintf(` resource "github_repository" "test" { @@ -597,6 +597,33 @@ func TestAccGithubRepository(t *testing.T) { }) }) + t.Run("create_private_with_forking_unset", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + repoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID) + + config := fmt.Sprintf(` +resource "github_repository" "test" { + name = "%s" + description = "A private repository with forking disabled" + visibility = "private" +} +`, repoName) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessHasOrgs(t) }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("github_repository.test", "visibility", "private"), + resource.TestCheckResourceAttr("github_repository.test", "allow_forking", "false"), + ), + }, + }, + }) + }) + t.Run("configures vulnerability alerts for a private repository", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) repoName := fmt.Sprintf("%sprv-vuln-%s", testResourcePrefix, randomID)