Skip to content

Commit

Permalink
Empty ruleset required_deployment_environments is now valid (#1942)
Browse files Browse the repository at this point in the history
* Empty ruleset required_deployment_environments is now valid

* Update github/respository_rules_utils.go

---------

Co-authored-by: Keegan Campbell <[email protected]>
  • Loading branch information
o-sama and kfcampbell authored Oct 25, 2023
1 parent fbcad03 commit b86c22c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion github/resource_github_repository_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
"required_deployment_environments": {
Type: schema.TypeList,
Required: true,
DefaultFunc: func() (interface{}, error) { return []string{}, nil },
Description: "The environments that must be successfully deployed to before branches can be merged.",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down
8 changes: 7 additions & 1 deletion github/respository_rules_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ func expandRules(input []interface{}, org bool) []*github.RepositoryRule {
// Required deployments rule
if !org {
if v, ok := rulesMap["required_deployments"].([]interface{}); ok && len(v) != 0 {
requiredDeploymentsMap := v[0].(map[string]interface{})
requiredDeploymentsMap := make(map[string]interface{})
// If the rule's block is present but has an empty environments list
if v[0] == nil {
requiredDeploymentsMap["required_deployment_environments"] = make([]interface{}, 0)
} else {
requiredDeploymentsMap = v[0].(map[string]interface{})
}
envs := make([]string, 0)
for _, v := range requiredDeploymentsMap["required_deployment_environments"].([]interface{}) {
envs = append(envs, v.(string))
Expand Down

0 comments on commit b86c22c

Please sign in to comment.