Merge pull request #20300 from hashicorp/jbardin/empty-string

allow implicit empty strings in lists
This commit is contained in:
James Bardin 2019-02-11 20:30:28 -05:00 committed by GitHub
commit fbde1b20f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 3 deletions

View File

@ -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", ""),
),
},
},
})
}

View File

@ -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
}