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 {