configs: BuildConfig sorts child modules by name

This is not strictly necessary, but since this is not a
performance-critical codepath we'll do this because it makes life easier
for callers that want to print out user-facing logs about build process,
or who are logging actions taken as part of a unit test.
This commit is contained in:
Martin Atkins 2018-02-14 12:46:13 -08:00
parent 51e5f7a56b
commit 3d551e25e0
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,8 @@
package configs package configs
import ( import (
"sort"
version "github.com/hashicorp/go-version" version "github.com/hashicorp/go-version"
"github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcl"
) )
@ -28,7 +30,16 @@ func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config,
calls := parent.Module.ModuleCalls calls := parent.Module.ModuleCalls
for _, call := range calls { // We'll sort the calls by their local names so that they'll appear in a
// predictable order in any logging that's produced during the walk.
callNames := make([]string, 0, len(calls))
for k := range calls {
callNames = append(callNames, k)
}
sort.Strings(callNames)
for _, callName := range callNames {
call := calls[callName]
path := make([]string, len(parent.Path)+1) path := make([]string, len(parent.Path)+1)
copy(path, parent.Path) copy(path, parent.Path)
path[len(path)-1] = call.Name path[len(path)-1] = call.Name