Skip to content

Commit b80f3f4

Browse files
committed
Pass requiredwith validation if defaultfunc present
1 parent 868827a commit b80f3f4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

helper/schema/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ func validateRequiredWithAttribute(
18171817
schema *Schema,
18181818
c *terraform.ResourceConfig) error {
18191819

1820-
if len(schema.RequiredWith) == 0 {
1820+
if len(schema.RequiredWith) == 0 || schema.DefaultFunc != nil {
18211821
return nil
18221822
}
18231823

helper/schema/schema_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8798,6 +8798,26 @@ func TestValidateRequiredWithAttributes(t *testing.T) {
87988798

87998799
Err: true,
88008800
},
8801+
"default func and required with": {
8802+
Schema: map[string]*Schema{
8803+
"foo": {
8804+
Type: TypeBool,
8805+
Optional: true,
8806+
},
8807+
"bar": {
8808+
Type: TypeBool,
8809+
Optional: true,
8810+
RequiredWith: []string{"foo"},
8811+
DefaultFunc: func() (interface{}, error) { return true, nil },
8812+
},
8813+
},
8814+
8815+
Config: map[string]interface{}{
8816+
"foo": true,
8817+
},
8818+
8819+
Err: false,
8820+
},
88018821
}
88028822

88038823
for tn, tc := range cases {

0 commit comments

Comments
 (0)