From 6bc52be0a5f373a5bdded6971b43e470c0ee841a Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 24 May 2017 12:31:22 -0400 Subject: [PATCH] check for IsComputed when validating a schema obj GH-14784 allowed nested structures to be validate, rather than relying on the raw value. However this still returns the same validation error if the structures contain a computed value, since Get will return the raw string in that case. This simply skips the validation in the IsComputed case, since there's nothing that can be checked. --- helper/schema/schema.go | 2 +- helper/schema/schema_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 88b35e08f..632672ae0 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -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())} diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 994c8866a..0a9583aa8 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -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{