Skip to content

Commit

Permalink
Merge pull request #14801 from hashicorp/jbardin/validate-computed-ob…
Browse files Browse the repository at this point in the history
…ject

check for IsComputed when validating a schema object
  • Loading branch information
jbardin authored May 24, 2017
2 parents e1d9ad4 + 6bc52be commit cd7c5cb
Show file tree
Hide file tree
Showing 2 changed files with 30 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 @@ -1374,7 +1374,7 @@ func (m schemaMap) validateObject(
schema map[string]*Schema,
c *terraform.ResourceConfig) ([]string, []error) {
raw, _ := c.Get(k)
if _, ok := raw.(map[string]interface{}); !ok {
if _, ok := raw.(map[string]interface{}); !ok && !c.IsComputed(k) {
return nil, []error{fmt.Errorf(
"%s: expected object, got %s",
k, reflect.ValueOf(raw).Kind())}
Expand Down
29 changes: 29 additions & 0 deletions helper/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3974,6 +3974,35 @@ func TestSchemaMap_Validate(t *testing.T) {
Err: false,
},

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

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

Vars: map[string]string{
"var.port": config.UnknownVariableValue,
},

Err: false,
},

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

0 comments on commit cd7c5cb

Please sign in to comment.