terraform: ResourceConfig.Get doesn't panic if exceed list bounds

[GH-210]
This commit is contained in:
Mitchell Hashimoto 2014-08-21 11:37:14 -07:00
parent 4a3dff2441
commit 9ecfdc350e
2 changed files with 19 additions and 0 deletions

View File

@ -149,6 +149,9 @@ func (c *ResourceConfig) get(
if err != nil {
return nil, false
}
if i >= int64(cv.Len()) {
return nil, false
}
current = cv.Index(int(i)).Interface()
}
default:

View File

@ -55,6 +55,22 @@ func TestResourceConfigGet(t *testing.T) {
Key: "foo",
Value: "bar",
},
{
Config: map[string]interface{}{
"foo": []interface{}{1, 2, 5},
},
Key: "foo.0",
Value: 1,
},
{
Config: map[string]interface{}{
"foo": []interface{}{1, 2, 5},
},
Key: "foo.5",
Value: nil,
},
}
for i, tc := range cases {