diff --git a/config/config_test.go b/config/config_test.go index 2ef68dae97..b391295c86 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -201,6 +201,12 @@ func TestConfigValidate_table(t *testing.T) { true, "cannot contain interp", }, + { + "nested types in variable default", + "validate-var-nested", + false, + "", + }, } for i, tc := range cases { diff --git a/config/interpolate_walk.go b/config/interpolate_walk.go index 81fa812087..ead3d102e1 100644 --- a/config/interpolate_walk.go +++ b/config/interpolate_walk.go @@ -206,6 +206,12 @@ func (w *interpolationWalker) Primitive(v reflect.Value) error { } func (w *interpolationWalker) replaceCurrent(v reflect.Value) { + // if we don't have at least 2 values, we're not going to find a map, but + // we could panic. + if len(w.cs) < 2 { + return + } + c := w.cs[len(w.cs)-2] switch c.Kind() { case reflect.Map: diff --git a/config/test-fixtures/validate-var-nested/main.tf b/config/test-fixtures/validate-var-nested/main.tf new file mode 100644 index 0000000000..a3d64647b1 --- /dev/null +++ b/config/test-fixtures/validate-var-nested/main.tf @@ -0,0 +1,6 @@ +variable "foo" { + default = [["foo", "bar"]] +} +variable "bar" { + default = [{foo = "bar"}] +}