mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 08:42:33 -04:00
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.
This commit is contained in:
parent
9d1dc7d41d
commit
5673af108f
1 changed files with 7 additions and 0 deletions
|
|
@ -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…
Reference in a new issue