Skip to content

Commit

Permalink
Fix MergeEnvVar panic (#4744)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheukt authored Jan 24, 2025
1 parent 2c8260e commit 29169e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions config/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
6 changes: 4 additions & 2 deletions config/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29169e5

Please sign in to comment.