@@ -238,6 +238,212 @@ resource "github_organization_ruleset" "test" {
238238 })
239239 })
240240
241+ t .Run ("create_ruleset_with_repository_property_exclude" , func (t * testing.T ) {
242+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
243+ rulesetName := fmt .Sprintf ("%s-repo-prop-exclude-ruleset-%s" , testResourcePrefix , randomID )
244+
245+ config := fmt .Sprintf (`
246+ resource "github_organization_ruleset" "test" {
247+ name = "%s"
248+ target = "branch"
249+ enforcement = "active"
250+
251+ conditions {
252+ repository_property {
253+ include = [{
254+ name = "tier"
255+ source = "custom"
256+ property_values = ["premium"]
257+ }]
258+ exclude = [{
259+ name = "archived"
260+ source = "system"
261+ property_values = ["true"]
262+ }]
263+ }
264+
265+ ref_name {
266+ include = ["~DEFAULT_BRANCH"]
267+ exclude = []
268+ }
269+ }
270+
271+ rules {
272+ required_linear_history = true
273+ }
274+ }
275+ ` , rulesetName )
276+
277+ resource .Test (t , resource.TestCase {
278+ PreCheck : func () { skipUnlessHasPaidOrgs (t ) },
279+ ProviderFactories : providerFactories ,
280+ Steps : []resource.TestStep {
281+ {
282+ Config : config ,
283+ Check : resource .ComposeTestCheckFunc (
284+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , rulesetName ),
285+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.#" , "1" ),
286+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.exclude.#" , "1" ),
287+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.exclude.0.name" , "archived" ),
288+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.exclude.0.source" , "system" ),
289+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.exclude.0.property_values.0" , "true" ),
290+ ),
291+ },
292+ },
293+ })
294+ })
295+
296+ t .Run ("create_ruleset_with_multiple_repository_properties" , func (t * testing.T ) {
297+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
298+ rulesetName := fmt .Sprintf ("%s-repo-prop-multiple-%s" , testResourcePrefix , randomID )
299+
300+ config := fmt .Sprintf (`
301+ resource "github_organization_ruleset" "test" {
302+ name = "%s"
303+ target = "branch"
304+ enforcement = "active"
305+
306+ conditions {
307+ repository_property {
308+ include = [
309+ {
310+ name = "environment"
311+ source = "custom"
312+ property_values = ["production"]
313+ },
314+ {
315+ name = "team"
316+ source = "custom"
317+ property_values = ["backend", "platform"]
318+ }
319+ ]
320+ exclude = []
321+ }
322+
323+ ref_name {
324+ include = ["~DEFAULT_BRANCH"]
325+ exclude = []
326+ }
327+ }
328+
329+ rules {
330+ required_signatures = true
331+ }
332+ }
333+ ` , rulesetName )
334+
335+ resource .Test (t , resource.TestCase {
336+ PreCheck : func () { skipUnlessHasPaidOrgs (t ) },
337+ ProviderFactories : providerFactories ,
338+ Steps : []resource.TestStep {
339+ {
340+ Config : config ,
341+ Check : resource .ComposeTestCheckFunc (
342+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , rulesetName ),
343+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.#" , "2" ),
344+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.0.name" , "environment" ),
345+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.0.property_values.0" , "production" ),
346+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.1.name" , "team" ),
347+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.1.property_values.#" , "2" ),
348+ ),
349+ },
350+ },
351+ })
352+ })
353+
354+ t .Run ("update_repository_property" , func (t * testing.T ) {
355+ randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
356+ rulesetName := fmt .Sprintf ("%s-repo-prop-update-%s" , testResourcePrefix , randomID )
357+
358+ config := fmt .Sprintf (`
359+ resource "github_organization_ruleset" "test" {
360+ name = "%s"
361+ target = "branch"
362+ enforcement = "active"
363+
364+ conditions {
365+ repository_property {
366+ include = [{
367+ name = "tier"
368+ source = "custom"
369+ property_values = ["basic"]
370+ }]
371+ exclude = []
372+ }
373+
374+ ref_name {
375+ include = ["~DEFAULT_BRANCH"]
376+ exclude = []
377+ }
378+ }
379+
380+ rules {
381+ creation = true
382+ }
383+ }
384+ ` , rulesetName )
385+
386+ configUpdated := fmt .Sprintf (`
387+ resource "github_organization_ruleset" "test" {
388+ name = "%s"
389+ target = "branch"
390+ enforcement = "active"
391+
392+ conditions {
393+ repository_property {
394+ include = [{
395+ name = "tier"
396+ source = "custom"
397+ property_values = ["premium", "enterprise"]
398+ }]
399+ exclude = [{
400+ name = "archived"
401+ source = "system"
402+ property_values = ["true"]
403+ }]
404+ }
405+
406+ ref_name {
407+ include = ["~DEFAULT_BRANCH"]
408+ exclude = []
409+ }
410+ }
411+
412+ rules {
413+ creation = true
414+ update = true
415+ }
416+ }
417+ ` , rulesetName )
418+
419+ resource .Test (t , resource.TestCase {
420+ PreCheck : func () { skipUnlessHasPaidOrgs (t ) },
421+ ProviderFactories : providerFactories ,
422+ Steps : []resource.TestStep {
423+ {
424+ Config : config ,
425+ Check : resource .ComposeTestCheckFunc (
426+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , rulesetName ),
427+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.0.property_values.#" , "1" ),
428+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.0.property_values.0" , "basic" ),
429+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.exclude.#" , "0" ),
430+ ),
431+ },
432+ {
433+ Config : configUpdated ,
434+ Check : resource .ComposeTestCheckFunc (
435+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "name" , rulesetName ),
436+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.0.property_values.#" , "2" ),
437+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.0.property_values.0" , "premium" ),
438+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.include.0.property_values.1" , "enterprise" ),
439+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.exclude.#" , "1" ),
440+ resource .TestCheckResourceAttr ("github_organization_ruleset.test" , "conditions.0.repository_property.0.exclude.0.name" , "archived" ),
441+ ),
442+ },
443+ },
444+ })
445+ })
446+
241447 t .Run ("create_push_ruleset" , func (t * testing.T ) {
242448 randomID := acctest .RandStringFromCharSet (5 , acctest .CharSetAlphaNum )
243449 rulesetName := fmt .Sprintf ("%s-push-ruleset-%s" , testResourcePrefix , randomID )
0 commit comments