diff --git a/helper/schema/schema.go b/helper/schema/schema.go index ee10bdd15..878901418 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -661,10 +661,10 @@ func (m schemaMap) diffMap( // Now we compare, preferring values from the config map for k, v := range configMap { - old := stateMap[k] + old, ok := stateMap[k] delete(stateMap, k) - if old == v && !all { + if old == v && ok && !all { continue } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 6f33b38ac..8d47d6af9 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -2063,6 +2063,38 @@ func TestSchemaMap_Diff(t *testing.T) { Err: false, }, + + // #52 - Map with empty value + { + Schema: map[string]*Schema{ + "vars": &Schema{ + Type: TypeMap, + }, + }, + + State: nil, + + Config: map[string]interface{}{ + "vars": map[string]interface{}{ + "foo": "", + }, + }, + + Diff: &terraform.InstanceDiff{ + Attributes: map[string]*terraform.ResourceAttrDiff{ + "vars.#": &terraform.ResourceAttrDiff{ + Old: "0", + New: "1", + }, + "vars.foo": &terraform.ResourceAttrDiff{ + Old: "", + New: "", + }, + }, + }, + + Err: false, + }, } for i, tc := range cases {