Merge pull request #14801 from hashicorp/jbardin/validate-computed-object

check for IsComputed when validating a schema object
This commit is contained in:
James Bardin 2017-05-24 13:31:05 -04:00 committed by GitHub
commit cd7c5cb61d
2 changed files with 30 additions and 1 deletions

View File

@ -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())}

View File

@ -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{