Skip to content

Commit

Permalink
Pass requiredwith validation if defaultfunc present
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpotter-rmn committed Feb 20, 2023
1 parent 868827a commit d7b35c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helper/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ func validateRequiredWithAttribute(
schema *Schema,
c *terraform.ResourceConfig) error {

if len(schema.RequiredWith) == 0 {
if len(schema.RequiredWith) == 0 || schema.DefaultFunc != nil {
return nil
}

Expand Down
20 changes: 20 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8798,6 +8798,26 @@ func TestValidateRequiredWithAttributes(t *testing.T) {

Err: true,
},
"default func and required with": {
Schema: map[string]*Schema{
"foo": {
Type: TypeBool,
Optional: true,
},
"bar": {
Type: TypeBool,
Optional: true,
RequiredWith: []string{"foo"},
DefaultFunc: func() (interface{}, error) { return true, nil },
},
},

Config: map[string]interface{}{
"foo": true,
},

Err: false,
},
}

for tn, tc := range cases {
Expand Down

0 comments on commit d7b35c8

Please sign in to comment.