diff --git a/config/module.go b/config/module.go index 903f1cf0ddc..8d6711664ea 100644 --- a/config/module.go +++ b/config/module.go @@ -133,6 +133,9 @@ func (m Module) Equals(other Module) bool { // MergeEnvVars will merge the provided environment variables with the existing Environment, with the existing Environment // taking priority. func (m *Module) MergeEnvVars(env map[string]string) { + if m.Environment == nil { + m.Environment = make(map[string]string) + } for k, v := range env { if _, ok := m.Environment[k]; ok { continue diff --git a/config/module_test.go b/config/module_test.go index 1d0471b092c..d6293185b5c 100644 --- a/config/module_test.go +++ b/config/module_test.go @@ -398,6 +398,13 @@ func TestFindMetaJSONFile(t *testing.T) { } func TestMergeEnvVars(t *testing.T) { + t.Run("nil", func(t *testing.T) { + m := Module{} + expected := map[string]string{"abc": "def", "hello": "world"} + + test.That(t, func() { m.MergeEnvVars(expected) }, test.ShouldNotPanic) + test.That(t, m.Environment, test.ShouldResemble, expected) + }) t.Run("empty", func(t *testing.T) { m := Module{Environment: map[string]string{}} expected := map[string]string{"abc": "def", "hello": "world"} diff --git a/config/reader.go b/config/reader.go index d0bd40e22f6..e80ca240e9d 100644 --- a/config/reader.go +++ b/config/reader.go @@ -630,8 +630,10 @@ func processConfig(unprocessedConfig *Config, fromCloud bool, logger logging.Log // add additional environment vars to modules // adding them here ensures that if the parsed API key changes, the module will be restarted with the updated environment. env := additionalModuleEnvVars(cfg.Cloud, cfg.Auth) - for _, m := range cfg.Modules { - m.MergeEnvVars(env) + if len(env) > 0 { + for _, m := range cfg.Modules { + m.MergeEnvVars(env) + } } // now that the attribute maps are converted, validate configs and get implicit dependencies for builtin resource models