Skip to content

Commit

Permalink
Fixes opentofu#539: Setting both "Type" and "NestedType" removes othe…
Browse files Browse the repository at this point in the history
…r validation error messages (opentofu#897)

Signed-off-by: Janos Bonic <86970079+janosdebugs@users.noreply.github.com>
  • Loading branch information
Janos authored and thumperward committed Jan 10, 2024
1 parent 471ec67 commit 6aa0774
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/configs/configschema/internal_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (a *Attribute) internalValidate(name, prefix string) error {

if a.Type != cty.NilType {
if a.NestedType != nil {
err = multierror.Append(fmt.Errorf("%s: Type and NestedType cannot both be set", name))
err = multierror.Append(err, fmt.Errorf("%s: Type and NestedType cannot both be set", name))
}
}

Expand Down
26 changes: 26 additions & 0 deletions internal/configs/configschema/internal_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ func TestBlockInternalValidate(t *testing.T) {
},
[]string{"foo: either Type or NestedType must be defined"},
},
"attribute with both type and nestedtype should not suppress other validation messages": {
&Block{
Attributes: map[string]*Attribute{
"foo": {
// These properties are here to make sure other errors are also reported.
Optional: true,
Required: true,
// Here's what we actually want to validate:
Type: cty.String,
NestedType: &Object{
Nesting: NestingSingle,
Attributes: map[string]*Attribute{
"foo": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
[]string{
"foo: cannot set both Optional and Required",
"foo: Type and NestedType cannot both be set",
},
},
/* FIXME: This caused errors when applied to existing providers (oci)
and cannot be enforced without coordination.
Expand Down

0 comments on commit 6aa0774

Please # to comment.