@@ -27,6 +27,10 @@ import (
2727// The function will panic if given a non-pointer as the Go value target,
2828// since that is considered to be a bug in the calling program.
2929func FromCtyValue (val cty.Value , target interface {}) error {
30+ return FromCtyValueTagged (val , target , "cty" )
31+ }
32+
33+ func FromCtyValueTagged (val cty.Value , target interface {}, tag string ) error {
3034 tVal := reflect .ValueOf (target )
3135 if tVal .Kind () != reflect .Ptr {
3236 panic ("target value is not a pointer" )
@@ -40,10 +44,10 @@ func FromCtyValue(val cty.Value, target interface{}) error {
4044 // unused capacity on the end of it, depending on how deeply-recursive
4145 // the given cty.Value is.
4246 path := make (cty.Path , 0 )
43- return fromCtyValue (val , tVal , path )
47+ return fromCtyValue (val , tVal , path , tag )
4448}
4549
46- func fromCtyValue (val cty.Value , target reflect.Value , path cty.Path ) error {
50+ func fromCtyValue (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
4751 ty := val .Type ()
4852
4953 deepTarget := fromCtyPopulatePtr (target , false )
@@ -89,17 +93,17 @@ func fromCtyValue(val cty.Value, target reflect.Value, path cty.Path) error {
8993
9094 switch {
9195 case ty .IsListType ():
92- return fromCtyList (val , target , path )
96+ return fromCtyList (val , target , path , tag )
9397 case ty .IsMapType ():
94- return fromCtyMap (val , target , path )
98+ return fromCtyMap (val , target , path , tag )
9599 case ty .IsSetType ():
96- return fromCtySet (val , target , path )
100+ return fromCtySet (val , target , path , tag )
97101 case ty .IsObjectType ():
98- return fromCtyObject (val , target , path )
102+ return fromCtyObject (val , target , path , tag )
99103 case ty .IsTupleType ():
100- return fromCtyTuple (val , target , path )
104+ return fromCtyTuple (val , target , path , tag )
101105 case ty .IsCapsuleType ():
102- return fromCtyCapsule (val , target , path )
106+ return fromCtyCapsule (val , target , path , tag )
103107 }
104108
105109 // We should never fall out here; reaching here indicates a bug in this
@@ -251,7 +255,7 @@ func fromCtyString(val cty.Value, target reflect.Value, path cty.Path) error {
251255 }
252256}
253257
254- func fromCtyList (val cty.Value , target reflect.Value , path cty.Path ) error {
258+ func fromCtyList (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
255259 switch target .Kind () {
256260
257261 case reflect .Slice :
@@ -273,7 +277,7 @@ func fromCtyList(val cty.Value, target reflect.Value, path cty.Path) error {
273277 }
274278
275279 targetElem := tv .Index (i )
276- err = fromCtyValue (val , targetElem , path )
280+ err = fromCtyValue (val , targetElem , path , tag )
277281 if err != nil {
278282 return true
279283 }
@@ -310,7 +314,7 @@ func fromCtyList(val cty.Value, target reflect.Value, path cty.Path) error {
310314 }
311315
312316 targetElem := target .Index (i )
313- err = fromCtyValue (val , targetElem , path )
317+ err = fromCtyValue (val , targetElem , path , tag )
314318 if err != nil {
315319 return true
316320 }
@@ -332,7 +336,7 @@ func fromCtyList(val cty.Value, target reflect.Value, path cty.Path) error {
332336 }
333337}
334338
335- func fromCtyMap (val cty.Value , target reflect.Value , path cty.Path ) error {
339+ func fromCtyMap (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
336340
337341 switch target .Kind () {
338342
@@ -356,7 +360,7 @@ func fromCtyMap(val cty.Value, target reflect.Value, path cty.Path) error {
356360 ks := key .AsString ()
357361
358362 targetElem := reflect .New (et )
359- err = fromCtyValue (val , targetElem , path )
363+ err = fromCtyValue (val , targetElem , path , tag )
360364
361365 tv .SetMapIndex (reflect .ValueOf (ks ), targetElem .Elem ())
362366
@@ -377,7 +381,7 @@ func fromCtyMap(val cty.Value, target reflect.Value, path cty.Path) error {
377381 }
378382}
379383
380- func fromCtySet (val cty.Value , target reflect.Value , path cty.Path ) error {
384+ func fromCtySet (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
381385 switch target .Kind () {
382386
383387 case reflect .Slice :
@@ -393,7 +397,7 @@ func fromCtySet(val cty.Value, target reflect.Value, path cty.Path) error {
393397 var err error
394398 val .ForEachElement (func (key cty.Value , val cty.Value ) bool {
395399 targetElem := tv .Index (i )
396- err = fromCtyValue (val , targetElem , path )
400+ err = fromCtyValue (val , targetElem , path , tag )
397401 if err != nil {
398402 return true
399403 }
@@ -422,7 +426,7 @@ func fromCtySet(val cty.Value, target reflect.Value, path cty.Path) error {
422426 var err error
423427 val .ForEachElement (func (key cty.Value , val cty.Value ) bool {
424428 targetElem := target .Index (i )
425- err = fromCtyValue (val , targetElem , path )
429+ err = fromCtyValue (val , targetElem , path , tag )
426430 if err != nil {
427431 return true
428432 }
@@ -444,14 +448,14 @@ func fromCtySet(val cty.Value, target reflect.Value, path cty.Path) error {
444448 }
445449}
446450
447- func fromCtyObject (val cty.Value , target reflect.Value , path cty.Path ) error {
451+ func fromCtyObject (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
448452
449453 switch target .Kind () {
450454
451455 case reflect .Struct :
452456
453457 attrTypes := val .Type ().AttributeTypes ()
454- targetFields := structTagIndices (target .Type ())
458+ targetFields := structTagIndices (target .Type (), tag )
455459
456460 path = append (path , nil )
457461
@@ -482,7 +486,7 @@ func fromCtyObject(val cty.Value, target reflect.Value, path cty.Path) error {
482486 ev := val .GetAttr (k )
483487
484488 targetField := target .Field (fieldIdx )
485- err := fromCtyValue (ev , targetField , path )
489+ err := fromCtyValue (ev , targetField , path , tag )
486490 if err != nil {
487491 return err
488492 }
@@ -498,7 +502,7 @@ func fromCtyObject(val cty.Value, target reflect.Value, path cty.Path) error {
498502 }
499503}
500504
501- func fromCtyTuple (val cty.Value , target reflect.Value , path cty.Path ) error {
505+ func fromCtyTuple (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
502506
503507 switch target .Kind () {
504508
@@ -521,7 +525,7 @@ func fromCtyTuple(val cty.Value, target reflect.Value, path cty.Path) error {
521525 ev := val .Index (cty .NumberIntVal (int64 (i )))
522526
523527 targetField := target .Field (i )
524- err := fromCtyValue (ev , targetField , path )
528+ err := fromCtyValue (ev , targetField , path , tag )
525529 if err != nil {
526530 return err
527531 }
@@ -537,7 +541,7 @@ func fromCtyTuple(val cty.Value, target reflect.Value, path cty.Path) error {
537541 }
538542}
539543
540- func fromCtyCapsule (val cty.Value , target reflect.Value , path cty.Path ) error {
544+ func fromCtyCapsule (val cty.Value , target reflect.Value , path cty.Path , tag string ) error {
541545
542546 if target .Kind () == reflect .Ptr {
543547 // Walk through indirection until we get to the last pointer,
0 commit comments