diff --git a/decoder.go b/decoder.go index 6b01859..02888d2 100644 --- a/decoder.go +++ b/decoder.go @@ -337,6 +337,14 @@ func (d *decoder) decodeMap(name string, node ast.Node, result reflect.Value) er continue } + // github.com/hashicorp/terraform/issue/5740 + if len(item.Keys) == 0 { + return &parser.PosError{ + Pos: node.Pos(), + Err: fmt.Errorf("%s: map must have string keys", name), + } + } + // Get the key we're dealing with, which is the first item keyStr := item.Keys[0].Token.Value().(string) diff --git a/decoder_test.go b/decoder_test.go index 3f07200..7ef6963 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -245,6 +245,14 @@ func TestDecode_interface(t *testing.T) { nil, }, + { + "nested_provider_bad.hcl", + true, + // This is not ideal but without significant rework of the decoder + // we get a partial result back as well as an error. + map[string]interface{}{}, + }, + { "object_list.json", false, diff --git a/test-fixtures/nested_provider_bad.hcl b/test-fixtures/nested_provider_bad.hcl new file mode 100644 index 0000000..94a753a --- /dev/null +++ b/test-fixtures/nested_provider_bad.hcl @@ -0,0 +1,5 @@ +resource "aws" "web" { + provider = "aws" { + region = "us-west-2" + } +}