Skip to content

Commit 1a1c5c6

Browse files
committed
Fix: Replace ExactlyOneOf with ConflictsWith/AtLeastOneOf for repository conditions
ExactlyOneOf has known issues with nested optional list blocks in Terraform SDK. Use ConflictsWith + AtLeastOneOf pattern for reliable "exactly one" validation across repository_name, repository_id, and repository_property conditions. Updated test expectations to match new error message format from ConflictsWith. Addresses feedback from PR #2356 comment r2968116244, references fix from #3235
1 parent 28a0de8 commit 1a1c5c6

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

github/resource_github_organization_ruleset.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
124124
},
125125
},
126126
"repository_property": {
127-
Type: schema.TypeList,
128-
Optional: true,
129-
MaxItems: 1,
130-
ExactlyOneOf: []string{"conditions.0.repository_property", "conditions.0.repository_name", "conditions.0.repository_id"},
131-
Description: "Conditions to target repositories by custom or system properties.",
127+
Type: schema.TypeList,
128+
Optional: true,
129+
MaxItems: 1,
130+
ConflictsWith: []string{"conditions.0.repository_id", "conditions.0.repository_name"},
131+
AtLeastOneOf: []string{"conditions.0.repository_name", "conditions.0.repository_id", "conditions.0.repository_property"},
132+
Description: "Conditions to target repositories by custom or system properties.",
132133
Elem: &schema.Resource{
133134
Schema: map[string]*schema.Schema{
134135
"include": {
@@ -195,11 +196,12 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
195196
},
196197
},
197198
"repository_name": {
198-
Type: schema.TypeList,
199-
Optional: true,
200-
MaxItems: 1,
201-
ExactlyOneOf: []string{"conditions.0.repository_property", "conditions.0.repository_name", "conditions.0.repository_id"},
202-
Description: "Targets repositories that match the specified name patterns.",
199+
Type: schema.TypeList,
200+
Optional: true,
201+
MaxItems: 1,
202+
ConflictsWith: []string{"conditions.0.repository_id", "conditions.0.repository_property"},
203+
AtLeastOneOf: []string{"conditions.0.repository_name", "conditions.0.repository_id", "conditions.0.repository_property"},
204+
Description: "Targets repositories that match the specified name patterns.",
203205
Elem: &schema.Resource{
204206
Schema: map[string]*schema.Schema{
205207
"include": {
@@ -228,10 +230,11 @@ func resourceGithubOrganizationRuleset() *schema.Resource {
228230
},
229231
},
230232
"repository_id": {
231-
Type: schema.TypeList,
232-
Optional: true,
233-
ExactlyOneOf: []string{"conditions.0.repository_property", "conditions.0.repository_name", "conditions.0.repository_id"},
234-
Description: "The repository IDs that the ruleset applies to. One of these IDs must match for the ruleset to apply.",
233+
Type: schema.TypeList,
234+
Optional: true,
235+
ConflictsWith: []string{"conditions.0.repository_name", "conditions.0.repository_property"},
236+
AtLeastOneOf: []string{"conditions.0.repository_name", "conditions.0.repository_id", "conditions.0.repository_property"},
237+
Description: "The repository IDs that the ruleset applies to. One of these IDs must match for the ruleset to apply.",
235238
Elem: &schema.Schema{
236239
Type: schema.TypeInt,
237240
},

github/resource_github_organization_ruleset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ resource "github_organization_ruleset" "test" {
10111011
Steps: []resource.TestStep{
10121012
{
10131013
Config: config,
1014-
ExpectError: regexp.MustCompile(`(?s)only one of.*conditions\.0\.repository_id.*conditions\.0\.repository_name.*conditions\.0\.repository_property.*can be specified`),
1014+
ExpectError: regexp.MustCompile(`(?s)Conflicting configuration arguments.*conditions\.0\.repository_(name|id|property).*conflicts with`),
10151015
},
10161016
},
10171017
})

0 commit comments

Comments
 (0)