Merge pull request #1824 from hashicorp/b-write-count-for-empty-maps
helper/schema: write "attr.#": "0" for empty maps
This commit is contained in:
commit
051ba78554
|
@ -141,7 +141,12 @@ func (w *MapFieldWriter) setMap(
|
|||
v := reflect.ValueOf(value)
|
||||
vs := make(map[string]interface{})
|
||||
|
||||
if value != nil {
|
||||
if value == nil {
|
||||
// The empty string here means the map is removed.
|
||||
w.result[k] = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
if v.Kind() != reflect.Map {
|
||||
return fmt.Errorf("%s: must be a map", k)
|
||||
}
|
||||
|
@ -152,13 +157,6 @@ func (w *MapFieldWriter) setMap(
|
|||
mv := v.MapIndex(mk)
|
||||
vs[mk.String()] = mv.Interface()
|
||||
}
|
||||
}
|
||||
|
||||
if len(vs) == 0 {
|
||||
// The empty string here means the map is removed.
|
||||
w.result[k] = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove the pure key since we're setting the full map value
|
||||
delete(w.result, k)
|
||||
|
|
|
@ -2539,7 +2539,9 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{},
|
||||
Attributes: map[string]string{
|
||||
"tags.#": "0",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue