helper/schema: support top-level TypeMap
This commit is contained in:
parent
699b2efa1c
commit
f43528957e
|
@ -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) {
|
||||||
resultSet = true
|
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 {
|
} else {
|
||||||
result = nil
|
result = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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{
|
||||||
|
|
Loading…
Reference in New Issue