diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index e73a449628..5cd2039e58 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -309,11 +309,6 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er } repoReq.Private = github.Bool(isPrivate) - if isPrivate { - repoReq.Visibility = github.String("private") - } else { - repoReq.Visibility = github.String("public") - } if template, ok := d.GetOk("template"); ok { templateConfigBlocks := template.([]interface{}) @@ -567,7 +562,7 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er log.Printf("[DEBUG] <<<<<<<<<<<<< Updating repository visibility from %s to %s", o, n) _, _, err = client.Repositories.Edit(ctx, owner, repoName, repoReq) if err != nil { - if !strings.Contains(err.Error(), "422 Visibility is already private") { + if !strings.Contains(err.Error(), fmt.Sprintf("422 Visibility is already %s", n.(string))) { return err } } diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index 2a0087ebdb..cbd2745016 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -844,6 +844,49 @@ func TestAccGithubRepositoryVisibility(t *testing.T) { }) }) + t.Run("creates repos with internal visibility", func(t *testing.T) { + t.Skip("organization used in automated tests does not support internal repositories") + + config := fmt.Sprintf(` + resource "github_repository" "internal" { + name = "tf-acc-test-visibility-internal-%s" + visibility = "internal" + } + `, randomID) + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.internal", "visibility", + "internal", + ), + ) + + testCase := func(t *testing.T, mode string) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessMode(t, mode) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: check, + }, + }, + }) + } + + t.Run("with an anonymous account", func(t *testing.T) { + t.Skip("anonymous account not supported for this operation") + }) + + t.Run("with an individual account", func(t *testing.T) { + testCase(t, individual) + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + }) + t.Run("updates repos to private visibility", func(t *testing.T) { config := fmt.Sprintf(`