mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
allow implicit empty strings in lists
The helper/schema handling of lists loses empty string values, but retains the correct count. Only re-count the values if the count is missing entirely, and allow our shims to re-populate the zero values.
This commit is contained in:
parent
3cecacb660
commit
1ca7531cc7
@ -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
Block a user