diff --git a/helper/schema/resource_data.go b/helper/schema/resource_data.go index 69ac090b3..fbef8c88b 100644 --- a/helper/schema/resource_data.go +++ b/helper/schema/resource_data.go @@ -372,9 +372,22 @@ func (d *ResourceData) getMap( if d.config != nil && source == getSourceConfig { // For config, we always set the result to exactly what was requested - if m, ok := d.config.Get(k); ok { - result = m.(map[string]interface{}) - resultSet = true + if mraw, ok := d.config.Get(k); ok { + switch m := mraw.(type) { + case []interface{}: + for _, innerRaw := range m { + for k, v := range innerRaw.(map[string]interface{}) { + result[k] = v + } + } + + resultSet = true + case map[string]interface{}: + result = m + resultSet = true + default: + panic(fmt.Sprintf("unknown type: %#v", mraw)) + } } else { result = nil } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 876393a9b..531891271 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -835,6 +835,35 @@ func TestSchemaMap_Diff(t *testing.T) { * Maps */ + { + Schema: map[string]*Schema{ + "config_vars": &Schema{ + Type: TypeMap, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "config_vars": []interface{}{ + map[string]interface{}{ + "bar": "baz", + }, + }, + }, + + Diff: &terraform.InstanceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "config_vars.bar": &terraform.ResourceAttrDiff{ + Old: "", + New: "baz", + }, + }, + }, + + Err: false, + }, + { Schema: map[string]*Schema{ "config_vars": &Schema{