diff --git a/internal/decoder/decoder.go b/internal/decoder/decoder.go index e3a8397..49b78f2 100644 --- a/internal/decoder/decoder.go +++ b/internal/decoder/decoder.go @@ -277,7 +277,8 @@ func decodeBlockToMap(block *schema.Block, val reflect.Value) { mv := reflect.MakeMap(val.Type()) for k, attr := range content.Attributes { - mv.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(attr.Value)) + key := removeAttrDot(k) + mv.SetMapIndex(reflect.ValueOf(key), reflect.ValueOf(attr.Value)) } blocksByType := content.Blocks.ByType() @@ -477,3 +478,12 @@ func getFieldTags(ty reflect.Type) *fieldTags { return ret } + +func removeAttrDot(v interface{}) interface{} { + str, ok := v.(string) + if !ok { + return v + } + + return strings.Trim(str, ".") +} diff --git a/internal/decoder/decoder_test.go b/internal/decoder/decoder_test.go index 53d570e..fc4e796 100644 --- a/internal/decoder/decoder_test.go +++ b/internal/decoder/decoder_test.go @@ -420,7 +420,10 @@ acl bye { "with flat block": {`acl hello { "localhost"; "local"; -}`, map[string]interface{}{}, map[string]interface{}{"acl": map[string]interface{}{"hello": []interface{}{"localhost", "local"}}}}} +}`, map[string]interface{}{}, map[string]interface{}{"acl": map[string]interface{}{"hello": []interface{}{"localhost", "local"}}}}, + "with dot attribute block": {`backend default { + .port = "8080"; +}`, map[string]interface{}{}, map[string]interface{}{"backend": map[string]interface{}{"default": map[string]interface{}{"port": "8080"}}}}} for n, tc := range testCases { t.Run(n, func(t *testing.T) {