Skip to content

Commit

Permalink
connect: interpolate task env in config values
Browse files Browse the repository at this point in the history
When configuring Consul Service Mesh, it's sometimes necessary to
provide dynamic value that are only known to Nomad at runtime. By
interpolating configuration values (in addition to configuration keys),
user are able to pass these dynamic values to Consul from their Nomad
jobs.
  • Loading branch information
lgfa29 committed Sep 1, 2022
1 parent 99ebd0a commit 00c5a8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client/taskenv/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ func interpolateMapStringInterface(taskEnv *TaskEnv, orig map[string]interface{}

m := make(map[string]interface{}, len(orig))
for k, v := range orig {
m[taskEnv.ReplaceEnv(k)] = v
envK := taskEnv.ReplaceEnv(k)
if vStr, ok := v.(string); ok {
m[envK] = taskEnv.ReplaceEnv(vStr)
} else {
m[envK] = v
}
}
return m
}
Expand Down
2 changes: 2 additions & 0 deletions client/taskenv/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func TestInterpolate_interpolateConnect(t *testing.T) {
},
Config: map[string]interface{}{
"${config1}": 1,
"port": "${port1}",
},
},
},
Expand Down Expand Up @@ -347,6 +348,7 @@ func TestInterpolate_interpolateConnect(t *testing.T) {
},
Config: map[string]interface{}{
"_config1": 1,
"port": "12345",
},
},
},
Expand Down

0 comments on commit 00c5a8b

Please sign in to comment.