diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index 56972f89d5..c635ee1277 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -277,6 +277,10 @@ func dataSourceGithubRepository() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "public": { + Type: schema.TypeBool, + Computed: true, + }, "status": { Type: schema.TypeString, Computed: true, diff --git a/github/resource_github_repository.go b/github/resource_github_repository.go index 9d756ac6c9..b81125fdcf 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -373,6 +373,12 @@ func resourceGithubRepository() *schema.Resource { Computed: true, Description: "URL to the repository on the web.", }, + "public": { + Type: schema.TypeBool, + Computed: true, + Optional: true, + Description: "Whether the GitHub Pages site is publicly visible. If set to `true`, the site is accessible to anyone on the internet. If set to `false`, the site will only be accessible to users who have at least `read` access to the repository that published the site.", + }, "status": { Type: schema.TypeString, Computed: true, @@ -1125,6 +1131,11 @@ func expandPagesUpdate(input []any) *github.PagesUpdate { } update.Source = &github.PagesSource{Branch: &sourceBranch, Path: &sourcePath} } + + // Only set the github.PagesUpdate public field if the value is a valid boolean. + if v, ok := pages["public"].(bool); ok && v != "" { + update.Public = github.Ptr(v) + } return update } @@ -1149,6 +1160,7 @@ func flattenPages(pages *github.Pages) []any { pagesMap["url"] = pages.GetURL() pagesMap["status"] = pages.GetStatus() + pagesMap["public"] = pages.GetPublic() pagesMap["cname"] = pages.GetCNAME() pagesMap["custom_404"] = pages.GetCustom404() pagesMap["html_url"] = pages.GetHTMLURL() diff --git a/github/resource_github_repository_test.go b/github/resource_github_repository_test.go index bd34c6f803..8c218e5dc6 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -1424,6 +1424,39 @@ func Test_expandPages(t *testing.T) { } }) + t.Run("manages private pages feature for a repository", func(t *testing.T) { + randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) + testRepoName := fmt.Sprintf("%sprivate-pages-%s", testResourcePrefix, randomID) + config := fmt.Sprintf(` + resource "github_repository" "test" { + name = "%s" + auto_init = true + pages { + source { + branch = "main" + } + public = false + } + } + `, testRepoName) + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("github_repository.test", "pages.0.public", "false"), + ) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { skipUnlessHasOrgs(t) }, + ProviderFactories: providerFactories, + Steps: []resource.TestStep{ + { + Config: config, + Check: check, + }, + }, + }) + }) +} + t.Run("forks a repository without error", func(t *testing.T) { randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) testRepoName := fmt.Sprintf("%sfork-%s", testResourcePrefix, randomID) diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index 864c2596a2..a6a66ddde7 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -156,6 +156,8 @@ The `pages` block supports the following: * `cname` - (Optional) The custom domain for the repository. This can only be set after the repository has been created. +* `public` - (Optional, Computed) Whether the GitHub Pages site is publicly visible. If set to `true`, the site is accessible to anyone on the internet. If set to `false`, the site will only be accessible to users who have at least `read` access to the repository that published the site. There is no single default: accounts without GitHub Enterprise are forced to have public pages; with Enterprise and Managed Users, pages can only be private; only Enterprise accounts without Managed Users can choose. See [About access control for GitHub Pages sites](https://docs.github.com/en/enterprise-cloud@latest/pages/getting-started-with-github-pages/changing-the-visibility-of-your-github-pages-site#about-access-control-for-github-pages-sites). The value is also computed from GitHub, so omitting it is safe. + #### GitHub Pages Source The `source` block supports the following: