@@ -20,7 +20,7 @@ var NameGenerator = func() string {
2020 return fmt .Sprintf ("id_%s" , ulid .MustNew (ulid .Timestamp (t ), entropy ))
2121}
2222
23- // Kind describes what kind of resource is represented by a Resource isntance .
23+ // Kind describes what kind of resource is represented by a Resource instance .
2424type Kind string
2525
2626// IsNamed returns true if this kind of resources contains a name.
@@ -65,7 +65,7 @@ func MakeResource(
6565 name = NameGenerator ()
6666 }
6767
68- r := NewResource (name , c .typ , c .kind , c .block , c .provider , c .parent )
68+ r := NewResource (name , c .typ , c .kind , c .block , c .provider , c .parent , t . CallStack () )
6969 if dict != nil && dict .Len () != 0 {
7070 if err := r .loadDict (dict ); err != nil {
7171 return nil , err
@@ -208,6 +208,8 @@ type Resource struct {
208208 parent * Resource
209209 dependencies []* Resource
210210 provisioners []* Provisioner
211+
212+ cs starlark.CallStack
211213}
212214
213215var _ starlark.Value = & Resource {}
@@ -217,7 +219,11 @@ var _ starlark.Comparable = &Resource{}
217219
218220// NewResource returns a new resource of the given kind, type based on the
219221// given configschema.Block.
220- func NewResource (name , typ string , k Kind , b * configschema.Block , provider * Provider , parent * Resource ) * Resource {
222+ func NewResource (
223+ name , typ string , k Kind ,
224+ b * configschema.Block , provider * Provider , parent * Resource ,
225+ cs starlark.CallStack ,
226+ ) * Resource {
221227 return & Resource {
222228 name : name ,
223229 typ : typ ,
@@ -226,6 +232,7 @@ func NewResource(name, typ string, k Kind, b *configschema.Block, provider *Prov
226232 values : NewValues (),
227233 provider : provider ,
228234 parent : parent ,
235+ cs : cs ,
229236 }
230237}
231238
@@ -337,11 +344,14 @@ func (r *Resource) attrBlock(name string, b *configschema.NestedBlock) (starlark
337344 return v .Starlark (), nil
338345 }
339346
347+ var output starlark.Value
340348 if b .MaxItems != 1 {
341- return r .values .Set (name , MustValue (NewResourceCollection (name , NestedKind , & b .Block , r .provider , r ))).Starlark (), nil
349+ output = NewNestedResourceCollection (name , b , r .provider , r )
350+ } else {
351+ output = NewResource ("" , name , NestedKind , & b .Block , r .provider , r , nil )
342352 }
343353
344- return r .values .Set (name , MustValue (NewResource ( "" , name , NestedKind , & b . Block , r . provider , r ) )).Starlark (), nil
354+ return r .values .Set (name , MustValue (output )).Starlark (), nil
345355}
346356
347357func (r * Resource ) attrValue (name string , attr * configschema.Attribute ) (starlark.Value , error ) {
@@ -559,3 +569,15 @@ func (r *Resource) doCompareSameType(y *Resource, depth int) (bool, error) {
559569
560570 return true , nil
561571}
572+
573+ func (r * Resource ) CallStack () starlark.CallStack {
574+ if r .cs != nil {
575+ return r .cs
576+ }
577+
578+ if r .parent != nil {
579+ return r .parent .CallStack ()
580+ }
581+
582+ return nil
583+ }
0 commit comments