Skip to content

Commit c568ac1

Browse files
fix: required_code_scanning missing from terraform state (#2701)
* Fix required_code_scanning missing from terraform state * fix: resolve build errors in respository_rules_utils.go * adds docs --------- Co-authored-by: Nick Floyd <nicholas.floyd.info@gmail.com>
1 parent d43be85 commit c568ac1

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

github/respository_rules_utils.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,28 @@ func flattenRules(rules []*github.RepositoryRule, org bool) []any {
658658
rule["min_entries_to_merge_wait_minutes"] = params.MinEntriesToMergeWaitMinutes
659659
rulesMap[v.Type] = []map[string]any{rule}
660660

661+
case "required_code_scanning":
662+
var params github.RequiredCodeScanningRuleParameters
663+
664+
err := json.Unmarshal(*v.Parameters, &params)
665+
if err != nil {
666+
log.Printf("[INFO] Unexpected error unmarshalling rule %s with parameters: %v",
667+
v.Type, v.Parameters)
668+
}
669+
670+
requiredCodeScanningToolSlice := make([]map[string]any, 0)
671+
for _, tool := range params.RequiredCodeScanningTools {
672+
requiredCodeScanningToolSlice = append(requiredCodeScanningToolSlice, map[string]any{
673+
"alerts_threshold": tool.AlertsThreshold,
674+
"security_alerts_threshold": tool.SecurityAlertsThreshold,
675+
"tool": tool.Tool,
676+
})
677+
}
678+
679+
rule := make(map[string]any)
680+
rule["required_code_scanning_tool"] = requiredCodeScanningToolSlice
681+
rulesMap[v.Type] = []map[string]any{rule}
682+
661683
case "file_path_restriction":
662684
var params github.RuleFileParameters
663685
err := json.Unmarshal(*v.Parameters, &params)

website/docs/r/organization_ruleset.html.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ resource "github_organization_ruleset" "example" {
5454
ref = "main"
5555
}
5656
}
57+
58+
required_code_scanning {
59+
required_code_scanning_tool {
60+
alerts_threshold = "errors"
61+
security_alerts_threshold = "high_or_higher"
62+
tool = "CodeQL"
63+
}
64+
}
5765
}
5866
}
5967

website/docs/r/repository_ruleset.html.markdown

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ resource "github_repository_ruleset" "example" {
4949
required_deployment_environments = ["test"]
5050
}
5151
52-
52+
required_code_scanning {
53+
required_code_scanning_tool {
54+
alerts_threshold = "errors"
55+
security_alerts_threshold = "high_or_higher"
56+
tool = "CodeQL"
57+
}
58+
}
5359
}
5460
}
5561

0 commit comments

Comments
 (0)