Skip to content

Commit

Permalink
helper/schema: fix validating nested objects
Browse files Browse the repository at this point in the history
When interpreting a nested object, we were validating against the "raw"
value, and not the interpolated value, causing incorrect errors.

This affects structures such as:

```tf
tags = "${list(map("foo", "bar"))}"
```

Prior to this, a complaint about "expected object, got string" since the
raw value is obviously a string, when the interpolated value is the
correct shape.
  • Loading branch information
mattrobenolt committed May 24, 2017
1 parent 76d4abd commit b9a3433
Show file tree
Hide file tree
Showing 2 changed files with 28 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 @@ -1373,7 +1373,7 @@ func (m schemaMap) validateObject(
k string,
schema map[string]*Schema,
c *terraform.ResourceConfig) ([]string, []error) {
raw, _ := c.GetRaw(k)
raw, _ := c.Get(k)
if _, ok := raw.(map[string]interface{}); !ok {
return nil, []error{fmt.Errorf(
"%s: expected object, got %s",
Expand Down
27 changes: 27 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3947,6 +3947,33 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: false,
},

"Good sub-resource, interpolated value": {
Schema: map[string]*Schema{
"ingress": &Schema{
Type: TypeList,
Optional: true,
Elem: &Resource{
Schema: map[string]*Schema{
"from": &Schema{
Type: TypeInt,
Required: true,
},
},
},
},
},

Config: map[string]interface{}{
"ingress": []interface{}{
`${map("from", "80")}`,
},
},

Vars: map[string]string{},

Err: false,
},

"Invalid/unknown field": {
Schema: map[string]*Schema{
"availability_zone": &Schema{
Expand Down

0 comments on commit b9a3433

Please sign in to comment.