From 8e7fc240f91e659c6a3f27d2ae6c54299865789d Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Wed, 16 Sep 2015 23:26:27 +0300 Subject: [PATCH 1/2] schema: delete non existing values We need to set the value to an empty value so the state file does indeed change the value. Otherwise the obsolote value is still intact and doesn't get changed at all. This means `terraform show` still shows the obsolote value when the particular value is not existing anymore. This is due the AWS API which is returning a null instead of an empty string. --- helper/schema/field_writer_map.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helper/schema/field_writer_map.go b/helper/schema/field_writer_map.go index 3e9b047192e7..ea877e147eb1 100644 --- a/helper/schema/field_writer_map.go +++ b/helper/schema/field_writer_map.go @@ -207,7 +207,8 @@ func (w *MapFieldWriter) setPrimitive( k := strings.Join(addr, ".") if v == nil { - delete(w.result, k) + // The empty string here means the value is removed. + w.result[k] = "" return nil } From f269d4fc8ce9e389ec5355df05a53fcd907e907c Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Wed, 16 Sep 2015 23:35:10 +0300 Subject: [PATCH 2/2] schema: add test for nil string case --- helper/schema/field_writer_map_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/helper/schema/field_writer_map_test.go b/helper/schema/field_writer_map_test.go index 8cf8100f2cd4..c9373da5dd18 100644 --- a/helper/schema/field_writer_map_test.go +++ b/helper/schema/field_writer_map_test.go @@ -97,6 +97,15 @@ func TestMapFieldWriter(t *testing.T) { }, }, + "string nil": { + []string{"string"}, + nil, + false, + map[string]string{ + "string": "", + }, + }, + "list of resources": { []string{"listResource"}, []interface{}{