mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
ResourceConfig.get should never return (nil, true)
Fixes a case where ResourceConfig.get inadvertently returns a nil value. Add an integration test where assigning a map to a list via interpolation would panic.
This commit is contained in:
parent
3920460220
commit
68ba2d6ff0
@ -393,6 +393,40 @@ resource "test_resource" "foo" {
|
||||
})
|
||||
}
|
||||
|
||||
// Reproduces plan-time panic when the wrong type is interpolated in a list of
|
||||
// maps.
|
||||
// TODO: this should return a type error, rather than silently setting an empty
|
||||
// list
|
||||
func TestResource_dataSourceListMapPanic(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 = "val"
|
||||
required_map = {x = "y"}
|
||||
list_of_map = "${var.maplist}"
|
||||
}
|
||||
|
||||
variable "maplist" {
|
||||
type = "list"
|
||||
|
||||
default = [
|
||||
{a = "b"}
|
||||
]
|
||||
}
|
||||
`),
|
||||
ExpectError: nil,
|
||||
Check: func(s *terraform.State) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckResourceDestroy(s *terraform.State) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -316,7 +316,8 @@ func (c *ResourceConfig) get(
|
||||
// prefix so were split as path components above.
|
||||
actualKey := strings.Join(parts[i-1:], ".")
|
||||
if prevMap, ok := previous.(map[string]interface{}); ok {
|
||||
return prevMap[actualKey], true
|
||||
v, ok := prevMap[actualKey]
|
||||
return v, ok
|
||||
}
|
||||
|
||||
return nil, false
|
||||
|
Loading…
Reference in New Issue
Block a user