From b9a3433f6b7ca851b0c8b85c20c56579620422cf Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Wed, 24 May 2017 01:04:25 -0700 Subject: [PATCH] helper/schema: fix validating nested objects 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. --- helper/schema/schema.go | 2 +- helper/schema/schema_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 32d172139..88b35e08f 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -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", diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 3f8ca2329..994c8866a 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -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{