From 3d551e25e01bd95c190766869bf0260debe07ead Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 14 Feb 2018 12:46:13 -0800 Subject: [PATCH] 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. --- configs/config_build.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/configs/config_build.go b/configs/config_build.go index 7aca4f1c5..b33d121e4 100644 --- a/configs/config_build.go +++ b/configs/config_build.go @@ -1,6 +1,8 @@ package configs import ( + "sort" + version "github.com/hashicorp/go-version" "github.com/hashicorp/hcl2/hcl" ) @@ -28,7 +30,16 @@ func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config, 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) copy(path, parent.Path) path[len(path)-1] = call.Name