@@ -13,18 +13,22 @@ func TestGithubOrganizationRulesets(t *testing.T) {
1313 t .Run ("create_branch_ruleset" , func (t * testing.T ) {
1414 randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
1515 repoName := fmt .Sprintf ("%srepo-org-ruleset-%s" , testResourcePrefix , randomID )
16+ rulesetName := fmt .Sprintf ("%s-branch-ruleset-%s" , testResourcePrefix , randomID )
17+
18+ workflowFilePath := ".github/workflows/echo.yaml"
1619
1720 config := fmt .Sprintf (`
1821resource "github_repository" "test" {
1922 name = "%s"
2023 visibility = "private"
2124 auto_init = true
25+ ignore_vulnerability_alerts_during_read = true
2226}
2327
2428resource "github_repository_file" "workflow_file" {
2529 repository = github_repository.test.name
2630 branch = "main"
27- file = ".github/workflows/echo.yaml "
31+ file = "%[3]s "
2832 content = "name: Echo Workflow\n\non: [pull_request]\n\njobs:\n echo:\n runs-on: linux\n steps:\n - run: echo \"Hello, world!\"\n"
2933 commit_message = "Managed by Terraform"
3034 commit_author = "Terraform User"
@@ -37,7 +41,7 @@ resource "github_actions_repository_access_level" "test" {
3741}
3842
3943resource "github_organization_ruleset" "test" {
40- name = "test-% s"
44+ name = "%[2] s"
4145 target = "branch"
4246 enforcement = "active"
4347
@@ -81,6 +85,7 @@ resource "github_organization_ruleset" "test" {
8185 required_signatures = false
8286
8387 pull_request {
88+ allowed_merge_methods = ["merge", "rebase", "squash"]
8489 required_approving_review_count = 2
8590 required_review_thread_resolution = true
8691 require_code_owner_review = true
@@ -101,8 +106,9 @@ resource "github_organization_ruleset" "test" {
101106 required_workflows {
102107 do_not_enforce_on_create = true
103108 required_workflow {
104- path = ".github/workflows/echo.yaml "
109+ path = "%[3]s "
105110 repository_id = github_repository.test.repo_id
111+ ref = "main" # Default ref is master
106112 }
107113 }
108114
@@ -123,8 +129,9 @@ resource "github_organization_ruleset" "test" {
123129
124130 non_fast_forward = true
125131 }
132+ depends_on = [github_repository_file.workflow_file]
126133}
127- ` , repoName , randomID )
134+ ` , repoName , rulesetName , workflowFilePath )
128135
129136 resource .Test (t , resource.TestCase {
130137 PreCheck : func () { skipUnlessHasPaidOrgs (t ) },
@@ -133,7 +140,7 @@ resource "github_organization_ruleset" "test" {
133140 {
134141 Config : config ,
135142 Check : resource .ComposeTestCheckFunc (
136- resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , "test" ),
143+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , rulesetName ),
137144 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "target" , "branch" ),
138145 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "enforcement" , "active" ),
139146 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "bypass_actors.#" , "3" ),
@@ -145,8 +152,8 @@ resource "github_organization_ruleset" "test" {
145152 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "bypass_actors.2.actor_id" , "1" ),
146153 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "bypass_actors.2.actor_type" , "OrganizationAdmin" ),
147154 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "bypass_actors.2.bypass_mode" , "always" ),
148- resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.required_workflows.0.o_not_enforce_on_create " , "true" ), resource . TestCheckResourceAttr ( "github_organization_ruleset.test" , "rules.0.required_workflows.0.required_workflow.0.path" , "path/to/workflow.yaml " ),
149- resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.required_workflows.0.required_workflow.0.repository_id " , "1234" ),
155+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.required_workflows.0.do_not_enforce_on_create " , "true" ),
156+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.required_workflows.0.required_workflow.0.path " , workflowFilePath ),
150157 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.required_code_scanning.0.required_code_scanning_tool.0.alerts_threshold" , "errors" ),
151158 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.required_code_scanning.0.required_code_scanning_tool.0.security_alerts_threshold" , "high_or_higher" ),
152159 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.required_code_scanning.0.required_code_scanning_tool.0.tool" , "CodeQL" ),
@@ -158,10 +165,11 @@ resource "github_organization_ruleset" "test" {
158165
159166 t .Run ("create_push_ruleset" , func (t * testing.T ) {
160167 randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
168+ rulesetName := fmt .Sprintf ("%s-push-ruleset-%s" , testResourcePrefix , randomID )
161169
162170 config := fmt .Sprintf (`
163171resource "github_organization_ruleset" "test" {
164- name = "test- %s"
172+ name = "%s"
165173 target = "push"
166174 enforcement = "active"
167175
@@ -200,15 +208,15 @@ resource "github_organization_ruleset" "test" {
200208 }
201209
202210 max_file_size {
203- max_file_size = 1048576
211+ max_file_size = 99
204212 }
205213
206214 file_extension_restriction {
207215 restricted_file_extensions = ["*.zip"]
208216 }
209217 }
210218}
211- ` , randomID )
219+ ` , rulesetName )
212220
213221 resource .Test (t , resource.TestCase {
214222 PreCheck : func () { skipUnlessHasPaidOrgs (t ) },
@@ -217,7 +225,7 @@ resource "github_organization_ruleset" "test" {
217225 {
218226 Config : config ,
219227 Check : resource .ComposeTestCheckFunc (
220- resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , "test" ),
228+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , rulesetName ),
221229 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "target" , "push" ),
222230 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "enforcement" , "active" ),
223231 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "bypass_actors.#" , "3" ),
@@ -230,7 +238,7 @@ resource "github_organization_ruleset" "test" {
230238 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "bypass_actors.2.actor_type" , "OrganizationAdmin" ),
231239 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "bypass_actors.2.bypass_mode" , "always" ),
232240 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.file_path_restriction.0.restricted_file_paths.0" , "test.txt" ),
233- resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.max_file_size.0.max_file_size" , "1048576 " ),
241+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.max_file_size.0.max_file_size" , "99 " ),
234242 resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "rules.0.file_extension_restriction.0.restricted_file_extensions.0" , "*.zip" ),
235243 ),
236244 },
@@ -289,10 +297,11 @@ resource "github_organization_ruleset" "test" {
289297
290298 t .Run ("update_clear_bypass_actors" , func (t * testing.T ) {
291299 randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
300+ rulesetName := fmt .Sprintf ("%s-bypass-ruleset-%s" , testResourcePrefix , randomID )
292301
293302 config := fmt .Sprintf (`
294303resource "github_organization_ruleset" "test" {
295- name = "test- %s"
304+ name = "%s"
296305 target = "branch"
297306 enforcement = "active"
298307
@@ -329,11 +338,11 @@ resource "github_organization_ruleset" "test" {
329338 creation = true
330339 }
331340}
332- ` , randomID )
341+ ` , rulesetName )
333342
334- configUpdated := `
343+ configUpdated := fmt . Sprintf ( `
335344resource "github_organization_ruleset" "test" {
336- name = "test-bypass "
345+ name = "%s "
337346 target = "branch"
338347 enforcement = "active"
339348
@@ -353,7 +362,7 @@ resource "github_organization_ruleset" "test" {
353362 creation = true
354363 }
355364}
356- `
365+ ` , rulesetName )
357366
358367 resource .Test (t , resource.TestCase {
359368 PreCheck : func () { skipUnlessHasPaidOrgs (t ) },
0 commit comments