hcl2template: split GetVarsByType in two functions

GetVarsByType is a function that gets a list of Traversals from a hcl
Block.

This approach works when what we are visiting is indeed one, however
when we can get an immediate list of Traversals, but want to filter them
based on their roots, we have to reimplement parts of that function.

Therefore, we split this function in two, GetVarsByType still keeps its
current behaviour, but the filtering step is exposed as another function
now: FilterTraversalsByType, so we can reuse it elsewhere.
nywilken.document-tmpdir
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 9d1dc7d41d
commit 5673af108f

@ -205,6 +205,13 @@ func GetVarsByType(block *hcl.Block, topLevelLabels ...string) []hcl.Traversal {
}
}
return FilterTraversalsByType(travs, topLevelLabels...)
}
// FilterTraversalsByType lets the caller filter the traversals per top-level type.
//
// This can then be used to detect dependencies between block types.
func FilterTraversalsByType(travs []hcl.Traversal, topLevelLabels ...string) []hcl.Traversal {
var rets []hcl.Traversal
for _, t := range travs {
varRootname := t.RootName()

Loading…
Cancel
Save