From 9ecfdc350ed44da64ab7134d7ff66601db99a6ee Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Aug 2014 11:37:14 -0700 Subject: [PATCH] terraform: ResourceConfig.Get doesn't panic if exceed list bounds [GH-210] --- terraform/resource.go | 3 +++ terraform/resource_test.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/terraform/resource.go b/terraform/resource.go index 29a58b3f2..e3435279e 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -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: diff --git a/terraform/resource_test.go b/terraform/resource_test.go index a7d4b75db..69886ccb5 100644 --- a/terraform/resource_test.go +++ b/terraform/resource_test.go @@ -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 {