helper/schema: support top-level TypeMap

This commit is contained in:
Mitchell Hashimoto 2014-10-08 17:35:14 -07:00
parent 699b2efa1c
commit f43528957e
2 changed files with 45 additions and 3 deletions

View File

@ -372,9 +372,22 @@ func (d *ResourceData) getMap(
if d.config != nil && source == getSourceConfig { if d.config != nil && source == getSourceConfig {
// For config, we always set the result to exactly what was requested // For config, we always set the result to exactly what was requested
if m, ok := d.config.Get(k); ok { if mraw, ok := d.config.Get(k); ok {
result = m.(map[string]interface{}) switch m := mraw.(type) {
case []interface{}:
for _, innerRaw := range m {
for k, v := range innerRaw.(map[string]interface{}) {
result[k] = v
}
}
resultSet = true resultSet = true
case map[string]interface{}:
result = m
resultSet = true
default:
panic(fmt.Sprintf("unknown type: %#v", mraw))
}
} else { } else {
result = nil result = nil
} }

View File

@ -835,6 +835,35 @@ func TestSchemaMap_Diff(t *testing.T) {
* Maps * 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{ Schema: map[string]*Schema{
"config_vars": &Schema{ "config_vars": &Schema{