diff --git a/github/data_source_github_repository.go b/github/data_source_github_repository.go index ed2a30143b..426cf0f4ce 100644 --- a/github/data_source_github_repository.go +++ b/github/data_source_github_repository.go @@ -270,6 +270,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 f28cc4c6e8..9d6d269b5a 100644 --- a/github/resource_github_repository.go +++ b/github/resource_github_repository.go @@ -295,9 +295,14 @@ func resourceGithubRepository() *schema.Resource { Computed: true, Description: "URL to the repository on the web.", }, + "public": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the rendered GitHub Pages site is publicly availabe.", + }, "status": { Type: schema.TypeString, - Computed: true, + Optional: true, Description: "The GitHub Pages site's build status e.g. building or built.", }, "url": { @@ -913,7 +918,12 @@ func expandPages(input []interface{}) *github.Pages { buildType = github.String(v) } - return &github.Pages{Source: source, BuildType: buildType} + var public *bool + // Only set the github.PagesUpdate public field if the value is a valid boolean. + if v, ok := pages["public"].(bool); ok { + public = github.Bool(v) + } + return &github.Pages{Source: source, BuildType: buildType, Public: public} } func expandPagesUpdate(input []interface{}) *github.PagesUpdate { @@ -948,6 +958,11 @@ func expandPagesUpdate(input []interface{}) *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 { + update.Public = github.Bool(v) + } return update } @@ -966,6 +981,7 @@ func flattenPages(pages *github.Pages) []interface{} { pagesMap["build_type"] = pages.GetBuildType() 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 e09505dac9..f8645c9fb6 100644 --- a/github/resource_github_repository_test.go +++ b/github/resource_github_repository_test.go @@ -1125,6 +1125,53 @@ func TestAccGithubRepositoryPages(t *testing.T) { t.Errorf("got %q; want %q", pages.GetSource().GetPath(), "/docs") } }) + + t.Run("manages private pages feature for a repository", func(t *testing.T) { + config := fmt.Sprintf(` + resource "github_repository" "test" { + name = "tf-acc-%s" + auto_init = true + pages { + source { + branch = "main" + } + public = false + } + } + `, randomID) + + check := resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "github_repository.test", "pages.0.public", + "false", + ), + ) + + 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 feature") + }) + + t.Run("with an individual account", func(t *testing.T) { + t.Skip("individual account not supported for this feature") + }) + + t.Run("with an organization account", func(t *testing.T) { + testCase(t, organization) + }) + }) } func TestAccGithubRepositorySecurity(t *testing.T) { diff --git a/website/docs/r/repository.html.markdown b/website/docs/r/repository.html.markdown index dc18add1d6..4d5f391397 100644 --- a/website/docs/r/repository.html.markdown +++ b/website/docs/r/repository.html.markdown @@ -136,6 +136,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) Whether the rendered GitHub Pages site is publicly available. + #### GitHub Pages Source #### The `source` block supports the following: