diff --git a/terraform/resource.go b/terraform/resource.go index a8cd8dd9f..2f5ebb5e7 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -346,7 +346,7 @@ func (c *ResourceConfig) get( if err != nil { return nil, false } - if i >= int64(cv.Len()) { + if int(i) < 0 || int(i) >= cv.Len() { return nil, false } current = cv.Index(int(i)).Interface() diff --git a/terraform/resource_test.go b/terraform/resource_test.go index 31d511e5c..4566492dc 100644 --- a/terraform/resource_test.go +++ b/terraform/resource_test.go @@ -158,6 +158,14 @@ func TestResourceConfigGet(t *testing.T) { Value: nil, }, + { + Config: map[string]interface{}{ + "foo": []interface{}{1, 2, 5}, + }, + Key: "foo.-1", + Value: nil, + }, + // get from map { Config: map[string]interface{}{