@@ -13,6 +13,10 @@ import (
1313)
1414
1515func TestAccGithubRepositoryRuleset(t *testing.T) {
16+ baseVisibility := "public"
17+ if testAccConf.authMode == enterprise {
18+ baseVisibility = "private" // Enable tests to run on GHEC EMU
19+ }
1620 t.Run("create_branch_ruleset", func(t *testing.T) {
1721 randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1822 repoName := fmt.Sprintf("%srepo-ruleset-%s", testResourcePrefix, randomID)
@@ -23,6 +27,7 @@ resource "github_repository" "test" {
2327 auto_init = true
2428 default_branch = "main"
2529 vulnerability_alerts = true
30+ visibility = "%s"
2631}
2732
2833resource "github_repository_environment" "example" {
@@ -112,7 +117,7 @@ resource "github_repository_ruleset" "test" {
112117 }
113118 }
114119}
115- `, repoName)
120+ `, repoName, baseVisibility )
116121
117122 resource.Test(t, resource.TestCase{
118123 PreCheck: func() { skipUnauthenticated(t) },
@@ -150,6 +155,7 @@ resource "github_repository_ruleset" "test" {
150155 name = "%s"
151156 auto_init = false
152157 vulnerability_alerts = true
158+ visibility = "%s"
153159 }
154160
155161 resource "github_repository_environment" "example" {
@@ -179,7 +185,7 @@ resource "github_repository_ruleset" "test" {
179185 }
180186 }
181187 }
182- `, repoName)
188+ `, repoName, baseVisibility )
183189
184190 resource.Test(t, resource.TestCase{
185191 PreCheck: func() { skipUnlessMode(t, enterprise) },
@@ -231,7 +237,7 @@ resource "github_repository_ruleset" "test" {
231237 }
232238
233239 max_file_size {
234- max_file_size = 1048576
240+ max_file_size = 99
235241 }
236242
237243 file_extension_restriction {
@@ -252,14 +258,14 @@ resource "github_repository_ruleset" "test" {
252258 resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", "test-push"),
253259 resource.TestCheckResourceAttr("github_repository_ruleset.test", "target", "push"),
254260 resource.TestCheckResourceAttr("github_repository_ruleset.test", "enforcement", "active"),
255- resource.TestCheckResourceAttr("github_organization_ruleset .test", "bypass_actors.#", "2"),
256- resource.TestCheckResourceAttr("github_organization_ruleset .test", "bypass_actors.0.actor_type", "DeployKey"),
257- resource.TestCheckResourceAttr("github_organization_ruleset .test", "bypass_actors.0.bypass_mode", "always"),
258- resource.TestCheckResourceAttr("github_organization_ruleset .test", "bypass_actors.1.actor_id", "5"),
259- resource.TestCheckResourceAttr("github_organization_ruleset .test", "bypass_actors.1.actor_type", "RepositoryRole"),
260- resource.TestCheckResourceAttr("github_organization_ruleset .test", "bypass_actors.1.bypass_mode", "always"),
261+ resource.TestCheckResourceAttr("github_repository_ruleset .test", "bypass_actors.#", "2"),
262+ resource.TestCheckResourceAttr("github_repository_ruleset .test", "bypass_actors.0.actor_type", "DeployKey"),
263+ resource.TestCheckResourceAttr("github_repository_ruleset .test", "bypass_actors.0.bypass_mode", "always"),
264+ resource.TestCheckResourceAttr("github_repository_ruleset .test", "bypass_actors.1.actor_id", "5"),
265+ resource.TestCheckResourceAttr("github_repository_ruleset .test", "bypass_actors.1.actor_type", "RepositoryRole"),
266+ resource.TestCheckResourceAttr("github_repository_ruleset .test", "bypass_actors.1.bypass_mode", "always"),
261267 resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.file_path_restriction.0.restricted_file_paths.0", "test.txt"),
262- resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.max_file_size.0.max_file_size", "1048576 "),
268+ resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.max_file_size.0.max_file_size", "99 "),
263269 resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.file_extension_restriction.0.restricted_file_extensions.0", "*.zip"),
264270 ),
265271 },
@@ -275,13 +281,14 @@ resource "github_repository_ruleset" "test" {
275281
276282 config := `
277283resource "github_repository" "test" {
278- name = "%[1] s"
279- description = "Terraform acceptance tests %[2] s"
284+ name = "%s"
285+ description = "Terraform acceptance tests %s"
280286 vulnerability_alerts = true
287+ visibility = "%s"
281288}
282289
283290resource "github_repository_ruleset" "test" {
284- name = "%[3] s"
291+ name = "%s"
285292 repository = github_repository.test.id
286293 target = "branch"
287294 enforcement = "active"
@@ -297,13 +304,13 @@ resource "github_repository_ruleset" "test" {
297304 ProviderFactories: providerFactories,
298305 Steps: []resource.TestStep{
299306 {
300- Config: fmt.Sprintf(config, repoName, randomID, name),
307+ Config: fmt.Sprintf(config, repoName, randomID, baseVisibility, name),
301308 Check: resource.ComposeTestCheckFunc(
302309 resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", name),
303310 ),
304311 },
305312 {
306- Config: fmt.Sprintf(config, repoName, randomID, nameUpdated),
313+ Config: fmt.Sprintf(config, repoName, randomID, baseVisibility, nameUpdated),
307314 Check: resource.ComposeTestCheckFunc(
308315 resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", nameUpdated),
309316 ),
@@ -321,6 +328,7 @@ resource "github_repository" "test" {
321328 name = "%s"
322329 description = "Terraform acceptance tests %[1]s"
323330 auto_init = true
331+ visibility = "%s"
324332}
325333
326334resource "github_repository_ruleset" "test" {
@@ -351,13 +359,14 @@ resource "github_repository_ruleset" "test" {
351359 creation = true
352360 }
353361}
354- `, repoName)
362+ `, repoName, baseVisibility )
355363
356364 configUpdated := fmt.Sprintf(`
357365resource "github_repository" "test" {
358366 name = "%s"
359367 description = "Terraform acceptance tests %[1]s"
360368 auto_init = true
369+ visibility = "%s"
361370}
362371
363372resource "github_repository_ruleset" "test" {
@@ -377,7 +386,7 @@ resource "github_repository_ruleset" "test" {
377386 creation = true
378387 }
379388}
380- `, repoName)
389+ `, repoName, baseVisibility )
381390
382391 resource.Test(t, resource.TestCase{
383392 PreCheck: func() { skipUnauthenticated(t) },
@@ -406,11 +415,12 @@ resource "github_repository_ruleset" "test" {
406415 bypassMode := "always"
407416 bypassModeUpdated := "exempt"
408417
409- config := fmt.Sprintf( `
418+ config := `
410419resource "github_repository" "test" {
411420 name = "%s"
412421 description = "Terraform acceptance tests %s"
413422 auto_init = true
423+ visibility = "%s"
414424}
415425
416426resource "github_repository_ruleset" "test" {
@@ -436,20 +446,20 @@ resource "github_repository_ruleset" "test" {
436446 creation = true
437447 }
438448}
439- `, repoName, randomID, bypassMode)
449+ `
440450
441451 resource.Test(t, resource.TestCase{
442452 PreCheck: func() { skipUnauthenticated(t) },
443453 Providers: testAccProviders,
444454 Steps: []resource.TestStep{
445455 {
446- Config: fmt.Sprintf(config, randomID, bypassMode),
456+ Config: fmt.Sprintf(config, repoName, randomID, baseVisibility , bypassMode),
447457 Check: resource.ComposeTestCheckFunc(
448458 resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.bypass_mode", bypassMode),
449459 ),
450460 },
451461 {
452- Config: fmt.Sprintf(config, randomID, bypassModeUpdated),
462+ Config: fmt.Sprintf(config, repoName, randomID, baseVisibility , bypassModeUpdated),
453463 Check: resource.ComposeTestCheckFunc(
454464 resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.bypass_mode", bypassModeUpdated),
455465 ),
@@ -468,7 +478,8 @@ resource "github_repository_ruleset" "test" {
468478 description = "Terraform acceptance tests %s"
469479 auto_init = true
470480 default_branch = "main"
471- vulnerability_alerts = true
481+ vulnerability_alerts = true
482+ visibility = "%s"
472483 }
473484
474485 resource "github_repository_environment" "example" {
@@ -493,7 +504,7 @@ resource "github_repository_ruleset" "test" {
493504 creation = true
494505 }
495506 }
496- `, repoName, randomID)
507+ `, repoName, randomID, baseVisibility )
497508
498509 resource.Test(t, resource.TestCase{
499510 PreCheck: func() { skipUnauthenticated(t) },
@@ -515,6 +526,10 @@ resource "github_repository_ruleset" "test" {
515526}
516527
517528func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
529+ baseVisibility := "public"
530+ if testAccConf.authMode == enterprise {
531+ baseVisibility = "private" // Enable tests to run on GHEC EMU
532+ }
518533 t.Run("skips update and delete on archived repository", func(t *testing.T) {
519534 randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
520535 repoName := fmt.Sprintf("%srepo-ruleset-arch-%s", testResourcePrefix, randomID)
@@ -523,6 +538,7 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
523538 name = "%s"
524539 auto_init = true
525540 archived = false
541+ visibility = "%s"
526542 }
527543
528544 resource "github_repository_ruleset" "test" {
@@ -532,10 +548,10 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
532548 enforcement = "active"
533549 rules { creation = true }
534550 }
535- `, repoName)
551+ `, repoName, baseVisibility )
536552
537553 resource.Test(t, resource.TestCase{
538- PreCheck: func() { skipUnlessMode(t, individual ) },
554+ PreCheck: func() { skipUnauthenticated(t ) },
539555 Providers: testAccProviders,
540556 Steps: []resource.TestStep{
541557 {Config: config},
@@ -553,6 +569,7 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
553569 name = "%s"
554570 auto_init = true
555571 archived = true
572+ visibility = "%s"
556573 }
557574 resource "github_repository_ruleset" "test" {
558575 name = "test"
@@ -561,10 +578,10 @@ func TestAccGithubRepositoryRulesetArchived(t *testing.T) {
561578 enforcement = "active"
562579 rules { creation = true }
563580 }
564- `, repoName)
581+ `, repoName, baseVisibility )
565582
566583 resource.Test(t, resource.TestCase{
567- PreCheck: func() { skipUnlessMode(t, individual ) },
584+ PreCheck: func() { skipUnauthenticated(t ) },
568585 Providers: testAccProviders,
569586 Steps: []resource.TestStep{
570587 {Config: config, ExpectError: regexp.MustCompile("cannot create ruleset on archived repository")},
0 commit comments