Skip to content

Commit f76abcb

Browse files
committed
feat: Add support for members_can_change_repo_visibility in github_organization_settings
Also added support for the github_organization data source. Signed-off-by: James Alseth <jalseth@google.com>
1 parent 94f71cf commit f76abcb

6 files changed

+92
-102
lines changed

github/data_source_github_organization.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func dataSourceGithubOrganization() *schema.Resource {
141141
Type: schema.TypeBool,
142142
Computed: true,
143143
},
144+
"members_can_change_repo_visibility": {
145+
Type: schema.TypeBool,
146+
Computed: true,
147+
},
144148
"summary_only": {
145149
Type: schema.TypeBool,
146150
Optional: true,
@@ -265,6 +269,7 @@ func dataSourceGithubOrganizationRead(ctx context.Context, d *schema.ResourceDat
265269
_ = d.Set("dependency_graph_enabled_for_new_repositories", organization.GetDependencyGraphEnabledForNewRepos())
266270
_ = d.Set("secret_scanning_enabled_for_new_repositories", organization.GetSecretScanningEnabledForNewRepos())
267271
_ = d.Set("secret_scanning_push_protection_enabled_for_new_repositories", organization.GetSecretScanningPushProtectionEnabledForNewRepos())
272+
_ = d.Set("members_can_change_repo_visibility", organization.GetMembersCanChangeRepoVisibility())
268273
}
269274

270275
d.SetId(strconv.FormatInt(organization.GetID(), 10))

github/data_source_github_organization_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestAccGithubOrganizationDataSource(t *testing.T) {
4141
resource.TestCheckResourceAttrSet("data.github_organization.test", "dependency_graph_enabled_for_new_repositories"),
4242
resource.TestCheckResourceAttrSet("data.github_organization.test", "secret_scanning_enabled_for_new_repositories"),
4343
resource.TestCheckResourceAttrSet("data.github_organization.test", "secret_scanning_push_protection_enabled_for_new_repositories"),
44+
resource.TestCheckResourceAttrSet("data.github_organization.test", "members_can_change_repo_visibility"),
4445
)
4546

4647
resource.Test(t, resource.TestCase{

github/resource_github_organization_settings.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ func resourceGithubOrganizationSettings() *schema.Resource {
8181
Default: true,
8282
Description: "Whether or not organization members can create new repositories.",
8383
},
84+
"members_can_change_repo_visibility": {
85+
Type: schema.TypeBool,
86+
Optional: true,
87+
Default: true,
88+
Description: "Whether or not organization members can change the visibility of repositories.",
89+
},
8490
"members_can_create_internal_repositories": {
8591
Type: schema.TypeBool,
8692
Optional: true,
@@ -251,6 +257,9 @@ func buildOrganizationSettings(d *schema.ResourceData, isEnterprise bool) *githu
251257
if shouldInclude("members_can_create_repositories") {
252258
settings.MembersCanCreateRepos = new(d.Get("members_can_create_repositories").(bool))
253259
}
260+
if shouldInclude("members_can_change_repo_visibility") {
261+
settings.MembersCanChangeRepoVisibility = github.Ptr(d.Get("members_can_change_repo_visibility").(bool))
262+
}
254263
if shouldInclude("members_can_create_private_repositories") {
255264
settings.MembersCanCreatePrivateRepos = new(d.Get("members_can_create_private_repositories").(bool))
256265
}
@@ -357,6 +366,9 @@ func resourceGithubOrganizationSettingsCreateOrUpdate(d *schema.ResourceData, me
357366
if settings.MembersCanCreateRepos != nil {
358367
log.Printf("[DEBUG] MembersCanCreateRepos: %v", *settings.MembersCanCreateRepos)
359368
}
369+
if settings.MembersCanChangeRepoVisibility != nil {
370+
log.Printf("[DEBUG] MembersCanChangeRepoVisibility: %v", *settings.MembersCanChangeRepoVisibility)
371+
}
360372
if settings.MembersCanCreatePrivateRepos != nil {
361373
log.Printf("[DEBUG] MembersCanCreatePrivateRepos: %v", *settings.MembersCanCreatePrivateRepos)
362374
}
@@ -468,6 +480,9 @@ func resourceGithubOrganizationSettingsRead(d *schema.ResourceData, meta any) er
468480
if err = d.Set("members_can_create_repositories", orgSettings.GetMembersCanCreateRepos()); err != nil {
469481
return err
470482
}
483+
if err = d.Set("members_can_change_repo_visibility", orgSettings.GetMembersCanChangeRepoVisibility()); err != nil {
484+
return err
485+
}
471486
if err = d.Set("members_can_create_internal_repositories", orgSettings.GetMembersCanCreateInternalRepos()); err != nil {
472487
return err
473488
}

github/resource_github_organization_settings_test.go

Lines changed: 69 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
2525
has_repository_projects = true
2626
default_repository_permission = "read"
2727
members_can_create_repositories = true
28+
members_can_change_repo_visibility = true
2829
members_can_create_public_repositories = true
2930
members_can_create_private_repositories = true
3031
members_can_create_internal_repositories = false
@@ -42,10 +43,43 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
4243
}`
4344

4445
check := resource.ComposeTestCheckFunc(
45-
resource.TestCheckResourceAttr(
46-
"github_organization_settings.test",
47-
"billing_email", "test@example.com",
48-
),
46+
resource.TestCheckResourceAttr("github_organization_settings.test", "billing_email", "test@example.com"),
47+
resource.TestCheckResourceAttr("github_organization_settings.test", "company", "Test Company"),
48+
resource.TestCheckResourceAttr("github_organization_settings.test", "blog", "https://example.com"),
49+
resource.TestCheckResourceAttr("github_organization_settings.test", "email", "test@example.com"),
50+
resource.TestCheckResourceAttr("github_organization_settings.test", "twitter_username", "Test"),
51+
resource.TestCheckResourceAttr("github_organization_settings.test", "location", "Test Location"),
52+
resource.TestCheckResourceAttr("github_organization_settings.test", "name", "Test Name"),
53+
resource.TestCheckResourceAttr("github_organization_settings.test", "description", "Test Description"),
54+
resource.TestCheckResourceAttr("github_organization_settings.test", "has_organization_projects", "true"),
55+
resource.TestCheckResourceAttr("github_organization_settings.test", "has_repository_projects", "true"),
56+
resource.TestCheckResourceAttr("github_organization_settings.test", "default_repository_permission", "read"),
57+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_repositories", "true"),
58+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_change_repo_visibility", "true"),
59+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_public_repositories", "true"),
60+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_private_repositories", "true"),
61+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_internal_repositories", "false"),
62+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_pages", "true"),
63+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_public_pages", "true"),
64+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_private_pages", "true"),
65+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_fork_private_repositories", "true"),
66+
resource.TestCheckResourceAttr("github_organization_settings.test", "web_commit_signoff_required", "true"),
67+
resource.TestCheckResourceAttr("github_organization_settings.test", "advanced_security_enabled_for_new_repositories", "false"),
68+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependabot_alerts_enabled_for_new_repositories", "false"),
69+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependabot_security_updates_enabled_for_new_repositories", "false"),
70+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependency_graph_enabled_for_new_repositories", "false"),
71+
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_enabled_for_new_repositories", "false"),
72+
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_push_protection_enabled_for_new_repositories", "false"),
73+
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_validity_checks_enabled", "false"),
74+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_delete_repositories", "false"),
75+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_change_repo_visibility", "true"),
76+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_invite_outside_collaborators", "false"),
77+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_delete_issues", "false"),
78+
resource.TestCheckResourceAttr("github_organization_settings.test", "display_commenter_full_name_setting_enabled", "false"),
79+
resource.TestCheckResourceAttr("github_organization_settings.test", "readers_can_create_discussions", "false"),
80+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_teams", "false"),
81+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_view_dependency_insights", "false"),
82+
resource.TestCheckResourceAttr("github_organization_settings.test", "default_repository_branch", "main"),
4983
)
5084

5185
resource.Test(t, resource.TestCase{
@@ -84,14 +118,8 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
84118
}`, updatedBillingEmail, updatedCompany, updatedBlog),
85119
}
86120
checks := map[string]resource.TestCheckFunc{
87-
"before": resource.TestCheckResourceAttr(
88-
"github_organization_settings.test",
89-
"billing_email", billingEmail,
90-
),
91-
"after": resource.TestCheckResourceAttr(
92-
"github_organization_settings.test",
93-
"billing_email", updatedBillingEmail,
94-
),
121+
"before": resource.TestCheckResourceAttr("github_organization_settings.test", "billing_email", billingEmail),
122+
"after": resource.TestCheckResourceAttr("github_organization_settings.test", "billing_email", updatedBillingEmail),
95123
}
96124
resource.Test(t, resource.TestCase{
97125
PreCheck: func() { skipUnlessHasOrgs(t) },
@@ -150,6 +178,7 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
150178
resource "github_organization_settings" "test" {
151179
billing_email = "test@example.com"
152180
members_can_create_private_repositories = false
181+
members_can_change_repo_visibility = false
153182
members_can_create_internal_repositories = false
154183
members_can_fork_private_repositories = false
155184
web_commit_signoff_required = false
@@ -162,52 +191,19 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
162191
}`
163192

164193
check := resource.ComposeTestCheckFunc(
165-
resource.TestCheckResourceAttr(
166-
"github_organization_settings.test",
167-
"billing_email", "test@example.com",
168-
),
169-
resource.TestCheckResourceAttr(
170-
"github_organization_settings.test",
171-
"members_can_create_private_repositories", "false",
172-
),
173-
resource.TestCheckResourceAttr(
174-
"github_organization_settings.test",
175-
"members_can_create_internal_repositories", "false",
176-
),
177-
resource.TestCheckResourceAttr(
178-
"github_organization_settings.test",
179-
"members_can_fork_private_repositories", "false",
180-
),
181-
resource.TestCheckResourceAttr(
182-
"github_organization_settings.test",
183-
"web_commit_signoff_required", "false",
184-
),
185-
resource.TestCheckResourceAttr(
186-
"github_organization_settings.test",
187-
"advanced_security_enabled_for_new_repositories", "false",
188-
),
189-
resource.TestCheckResourceAttr(
190-
"github_organization_settings.test",
191-
"dependabot_alerts_enabled_for_new_repositories", "false",
192-
),
193-
resource.TestCheckResourceAttr(
194-
"github_organization_settings.test",
195-
"dependabot_security_updates_enabled_for_new_repositories", "false",
196-
),
197-
resource.TestCheckResourceAttr(
198-
"github_organization_settings.test",
199-
"dependency_graph_enabled_for_new_repositories", "false",
200-
),
201-
resource.TestCheckResourceAttr(
202-
"github_organization_settings.test",
203-
"secret_scanning_enabled_for_new_repositories", "false",
204-
),
205-
resource.TestCheckResourceAttr(
206-
"github_organization_settings.test",
207-
"secret_scanning_push_protection_enabled_for_new_repositories", "false",
208-
),
194+
resource.TestCheckResourceAttr("github_organization_settings.test", "billing_email", "test@example.com"),
195+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_private_repositories", "false"),
196+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_change_repo_visibility", "false"),
197+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_internal_repositories", "false"),
198+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_fork_private_repositories", "false"),
199+
resource.TestCheckResourceAttr("github_organization_settings.test", "web_commit_signoff_required", "false"),
200+
resource.TestCheckResourceAttr("github_organization_settings.test", "advanced_security_enabled_for_new_repositories", "false"),
201+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependabot_alerts_enabled_for_new_repositories", "false"),
202+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependabot_security_updates_enabled_for_new_repositories", "false"),
203+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependency_graph_enabled_for_new_repositories", "false"),
204+
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_enabled_for_new_repositories", "false"),
205+
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_push_protection_enabled_for_new_repositories", "false"),
209206
)
210-
211207
resource.Test(t, resource.TestCase{
212208
PreCheck: func() { skipUnlessHasOrgs(t) },
213209
ProviderFactories: providerFactories,
@@ -225,6 +221,7 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
225221
resource "github_organization_settings" "test" {
226222
billing_email = "test@example.com"
227223
members_can_create_private_repositories = false
224+
members_can_change_repo_visibility = true
228225
members_can_create_internal_repositories = true
229226
members_can_fork_private_repositories = false
230227
web_commit_signoff_required = true
@@ -237,52 +234,19 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
237234
}`
238235

239236
check := resource.ComposeTestCheckFunc(
240-
resource.TestCheckResourceAttr(
241-
"github_organization_settings.test",
242-
"billing_email", "test@example.com",
243-
),
244-
resource.TestCheckResourceAttr(
245-
"github_organization_settings.test",
246-
"members_can_create_private_repositories", "false",
247-
),
248-
resource.TestCheckResourceAttr(
249-
"github_organization_settings.test",
250-
"members_can_create_internal_repositories", "true",
251-
),
252-
resource.TestCheckResourceAttr(
253-
"github_organization_settings.test",
254-
"members_can_fork_private_repositories", "false",
255-
),
256-
resource.TestCheckResourceAttr(
257-
"github_organization_settings.test",
258-
"web_commit_signoff_required", "true",
259-
),
260-
resource.TestCheckResourceAttr(
261-
"github_organization_settings.test",
262-
"advanced_security_enabled_for_new_repositories", "false",
263-
),
264-
resource.TestCheckResourceAttr(
265-
"github_organization_settings.test",
266-
"dependabot_alerts_enabled_for_new_repositories", "true",
267-
),
268-
resource.TestCheckResourceAttr(
269-
"github_organization_settings.test",
270-
"dependabot_security_updates_enabled_for_new_repositories", "false",
271-
),
272-
resource.TestCheckResourceAttr(
273-
"github_organization_settings.test",
274-
"dependency_graph_enabled_for_new_repositories", "true",
275-
),
276-
resource.TestCheckResourceAttr(
277-
"github_organization_settings.test",
278-
"secret_scanning_enabled_for_new_repositories", "false",
279-
),
280-
resource.TestCheckResourceAttr(
281-
"github_organization_settings.test",
282-
"secret_scanning_push_protection_enabled_for_new_repositories", "true",
283-
),
237+
resource.TestCheckResourceAttr("github_organization_settings.test", "billing_email", "test@example.com"),
238+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_private_repositories", "false"),
239+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_change_repo_visibility", "true"),
240+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_internal_repositories", "true"),
241+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_fork_private_repositories", "false"),
242+
resource.TestCheckResourceAttr("github_organization_settings.test", "web_commit_signoff_required", "true"),
243+
resource.TestCheckResourceAttr("github_organization_settings.test", "advanced_security_enabled_for_new_repositories", "false"),
244+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependabot_alerts_enabled_for_new_repositories", "true"),
245+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependabot_security_updates_enabled_for_new_repositories", "false"),
246+
resource.TestCheckResourceAttr("github_organization_settings.test", "dependency_graph_enabled_for_new_repositories", "true"),
247+
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_enabled_for_new_repositories", "false"),
248+
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_push_protection_enabled_for_new_repositories", "true"),
284249
)
285-
286250
resource.Test(t, resource.TestCase{
287251
PreCheck: func() { skipUnlessHasOrgs(t) },
288252
ProviderFactories: providerFactories,
@@ -520,6 +484,7 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
520484
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_enabled_for_new_repositories", "true"),
521485
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_push_protection_enabled_for_new_repositories", "true"),
522486
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_private_repositories", "true"),
487+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_change_repo_visibility", "true"),
523488
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_internal_repositories", "true"),
524489
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_pages", "true"),
525490
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_public_pages", "true"),
@@ -551,6 +516,7 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
551516
secret_scanning_enabled_for_new_repositories = false
552517
secret_scanning_push_protection_enabled_for_new_repositories = false
553518
members_can_create_private_repositories = false
519+
members_can_change_repo_visibility = false
554520
members_can_create_internal_repositories = false
555521
members_can_create_pages = false
556522
members_can_create_public_pages = false
@@ -567,6 +533,7 @@ func TestAccGithubOrganizationSettings(t *testing.T) {
567533
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_enabled_for_new_repositories", "false"),
568534
resource.TestCheckResourceAttr("github_organization_settings.test", "secret_scanning_push_protection_enabled_for_new_repositories", "false"),
569535
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_private_repositories", "false"),
536+
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_change_repo_visibility", "false"),
570537
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_internal_repositories", "false"),
571538
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_pages", "false"),
572539
resource.TestCheckResourceAttr("github_organization_settings.test", "members_can_create_public_pages", "false"),

website/docs/d/organization.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ data "github_organization" "example" {
4343
* `default_repository_permission` - Default permission level members have for organization repositories.
4444
* `members_allowed_repository_creation_type` - The type of repository allowed to be created by members of the organization. Can be one of `ALL`, `PUBLIC`, `PRIVATE`, `NONE`.
4545
* `members_can_create_repositories` - Whether non-admin organization members can create repositories.
46+
* `members_can_change_repo_visibility` - Whether organization members can change the visibility of repositories.
4647
* `members_can_create_internal_repositories` - Whether organization members can create internal repositories.
4748
* `members_can_create_private_repositories` - Whether organization members can create private repositories.
4849
* `members_can_create_public_repositories` - Whether organization members can create public repositories.

0 commit comments

Comments
 (0)