diff --git a/nodes.go b/nodes.go index 47a3aee..efb207c 100644 --- a/nodes.go +++ b/nodes.go @@ -20,6 +20,8 @@ const ( // KeyTag indicates that the value of the field should be part of // the parent object block's key, not a property of that block KeyTag string = "key" + // LabelTag is an alias for KeyTag, hcl v2 has renamed key to label. + LabelTag string = "label" // SquashTag is attached to anonymous fields of a struct and indicates // to the encoder to lift the fields of that value into the parent @@ -220,7 +222,7 @@ func encodeMap(in reflect.Value) (ast.Node, []*ast.ObjectKey, error) { } // encodeStruct converts a struct type into an ast.ObjectType. An ast.ObjectKey -// may be returned if a KeyTag is present that should be used by a parent +// may be returned if a KeyTag/LabelTag is present that should be used by a parent // ast.ObjectItem if this node is nested. func encodeStruct(in reflect.Value) (ast.Node, []*ast.ObjectKey, error) { l := in.NumField() @@ -367,7 +369,7 @@ func extractFieldMeta(f reflect.StructField) (meta fieldMeta) { for _, tag := range tags[1:] { switch tag { - case KeyTag: + case KeyTag, LabelTag: meta.key = true case SquashTag: meta.squash = true diff --git a/nodes_test.go b/nodes_test.go index 4c90f52..e35e7e8 100644 --- a/nodes_test.go +++ b/nodes_test.go @@ -530,6 +530,10 @@ func TestExtractFieldMeta(t *testing.T) { `hcl:"bar,key"`, fieldMeta{name: "bar", key: true}, }, + { + `hcl:"bar,label"`, + fieldMeta{name: "bar", key: true}, + }, { `hcl:",squash"`, fieldMeta{name: fieldName, squash: true},