Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MergeEnvVar panic #4744

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading