Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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)
Expand Down