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:
James Bardin 2016-11-18 15:47:30 -05:00
parent 3920460220
commit 68ba2d6ff0
2 changed files with 36 additions and 1 deletions

View File

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

View File

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