Merge pull request #20300 from hashicorp/jbardin/empty-string
allow implicit empty strings in lists
This commit is contained in:
commit
fbde1b20f0
|
@ -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", ""),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue