Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
891a05c
Add public field to github pages
BartolottiLuca Jan 17, 2025
3dbe170
Merge pull request #1 from BartolottiLuca/repository-page-visibility
BartolottiLuca Jan 17, 2025
50725b5
Add public field to repository pages
BartolottiLuca Jan 17, 2025
c4b0fd3
add test and creation case
BartolottiLuca Jan 20, 2025
b590cd4
Update website/docs/r/repository.html.markdown
BartolottiLuca Jan 22, 2025
508035f
Merge branch 'main' into repository-page-visibility
BartolottiLuca Mar 2, 2025
bfeb23d
Merge branch 'main' into repository-page-visibility
BartolottiLuca Jul 23, 2025
17a2703
Merge branch 'main' into repository-page-visibility
BartolottiLuca Dec 5, 2025
abe0d9b
Update repository.html.markdown
BartolottiLuca Dec 5, 2025
5ae691a
Merge branch 'integrations:main' into main
BartolottiLuca Jan 13, 2026
3209324
Merge branch 'main' into repository-page-visibility
BartolottiLuca Jan 13, 2026
ca85b87
Update github/resource_github_repository.go
BartolottiLuca Jan 13, 2026
1c821b2
make status computed & remove unnecessary change
BartolottiLuca Jan 13, 2026
aba7639
Merge branch 'main' into repository-page-visibility
BartolottiLuca Jan 13, 2026
1461e99
Apply suggestion from @deiga
BartolottiLuca Jan 23, 2026
ffa8f54
Apply suggestion from @deiga
BartolottiLuca Jan 23, 2026
cd7bb22
new test convention and use testResourcePrefix
BartolottiLuca Jan 23, 2026
622a6ec
Merge branch 'integrations:main' into repository-page-visibility
BartolottiLuca Jan 23, 2026
9bfa849
Merge branch 'main' into repository-page-visibility
BartolottiLuca Jan 23, 2026
4c23d8f
Merge branch 'integrations:main' into main
BartolottiLuca Feb 13, 2026
310fd83
Merge branch 'main' into repository-page-visibility
BartolottiLuca Feb 13, 2026
94f32d5
apply suggestions
BartolottiLuca Feb 13, 2026
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
4 changes: 4 additions & 0 deletions github/data_source_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ func resourceGithubRepository() *schema.Resource {
Computed: true,
Description: "URL to the repository on the web.",
},
"public": {
Type: schema.TypeBool,
Computed: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This doesn't seem to get set anywhere and in the docs you write that it's optional. Did you mean to use Optional here? Should it have Default: false as well to remove the need for type-checking this later?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure which is the best option here. From the docs

To publish a GitHub Pages site privately, your organization must use GitHub Enterprise Cloud. For more information about how you can try GitHub Enterprise Cloud for free, see Setting up a trial of GitHub Enterprise Cloud.
If your enterprise uses Enterprise Managed Users, GitHub Pages sites can only be published as private, and all GitHub Pages sites are only accessible to other enterprise members. For more information about Enterprise Managed Users, see GitHub Pages limits.
If your organization uses GitHub Enterprise Cloud without Enterprise Managed Users, you can choose to publish your project sites privately or publicly to anyone on the internet.

So there's no clear default since:

  1. anyone without github enterprise will be forced to have public pages
  2. If you have enterprise and Enterprise Managed Users, the pages can only be private
  3. only users that have enterprise and not Enterprise Managed Users can choose between public and private

I guess Computed: true is safer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that does look problematic. I think that having only Computed: true prevents users from setting the value, which would be unwelcome for GHEC non-EMU cases.

Maybe you could check if the SDK sends the field or it's left blank, otherwise the Create and Update need to ensure it's not being sent unless explicitly set.

You're right that Default isn't a good idea, but I guess it needs to be Computed & Optional

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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions github/resource_github_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down