diff --git a/builtin/providers/test/resource_test.go b/builtin/providers/test/resource_test.go index 2b210d00b5..d697447726 100644 --- a/builtin/providers/test/resource_test.go +++ b/builtin/providers/test/resource_test.go @@ -677,3 +677,58 @@ resource "test_resource" "foo" { }, }) } + +func TestResource_emptyStrings(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource" "foo" { + required = "second" + required_map = { + a = "a" + } + + list = [""] +} +`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("test_resource.foo", "list.0", ""), + ), + }, + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource" "foo" { + required = "second" + required_map = { + a = "a" + } + + list = ["", "b"] +} +`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("test_resource.foo", "list.0", ""), + resource.TestCheckResourceAttr("test_resource.foo", "list.1", "b"), + ), + }, + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource" "foo" { + required = "second" + required_map = { + a = "a" + } + + list = [""] +} +`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("test_resource.foo", "list.0", ""), + ), + }, + }, + }) +} diff --git a/terraform/diff.go b/terraform/diff.go index 7828859fe2..f87db081fc 100644 --- a/terraform/diff.go +++ b/terraform/diff.go @@ -811,9 +811,10 @@ func (d *InstanceDiff) applyCollectionDiff(path []string, attrs map[string]strin } } - // Don't trust helper/schema to return a valid count, or even have one at - // all. - result[name+"."+idx] = countFlatmapContainerValues(name+"."+idx, result) + // Fill in the count value if it was missing for some reason: + if result[name+"."+idx] == "" { + result[name+"."+idx] = countFlatmapContainerValues(name+"."+idx, result) + } return result, nil }