diff --git a/config/config.go b/config/config.go index 8537f5629..83f5c6155 100644 --- a/config/config.go +++ b/config/config.go @@ -133,6 +133,7 @@ func (l *Loader) ResolvePath(relative string) (string, error) { } func (l *Loader) baseFiles() []string { + // Order is important: last files override values in the first files. return []string{_baseFile, l.Environment() + ".yaml"} } @@ -145,7 +146,9 @@ func (l *Loader) YamlProvider() ProviderFunc { return func() (Provider, error) { static := NewYAMLProviderFromFiles(false, l.getResolver(), l.getStaticFiles()...) interpolated := NewYAMLProviderWithExpand(false, l.getResolver(), os.LookupEnv, l.getFiles()...) - return NewProviderGroup("yaml", interpolated, static), nil + + // Interpolated files will have higher priority than static. + return NewProviderGroup("yaml", static, interpolated), nil } } diff --git a/config/yaml.go b/config/yaml.go index 1bd10effe..270da0a92 100644 --- a/config/yaml.go +++ b/config/yaml.go @@ -170,7 +170,7 @@ func NewYAMLProviderFromReader(readers ...io.ReadCloser) Provider { // and uses the mapping function to interpolated values in the underlying provider. func NewYAMLProviderFromReaderWithExpand(mapping func(string) (string, bool), readers ...io.ReadCloser) Provider { p := newYAMLProviderCore(readers...) - p.root.dfs(interpolate(mapping)) + p.root.applyOnAllNodes(interpolate(mapping)) return NewCachedProvider(p) } @@ -306,7 +306,7 @@ func (n *yamlNode) Children() []*yamlNode { return nodes } -func (n *yamlNode) dfs(expand func(string) string) { +func (n *yamlNode) applyOnAllNodes(expand func(string) string) { if n == nil { return } @@ -316,7 +316,7 @@ func (n *yamlNode) dfs(expand func(string) string) { } for _, c := range n.Children() { - c.dfs(expand) + c.applyOnAllNodes(expand) } }