Skip to content

Commit

Permalink
interpolate network.dns block on client (fixes hashicorp#11851)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvx committed Feb 8, 2022
1 parent 21f7d01 commit 02004de
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/taskenv/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
//
// Current interoperable fields:
// - Hostname
// - DNS
func InterpolateNetworks(taskEnv *TaskEnv, networks structs.Networks) structs.Networks {

// Guard against not having a valid taskEnv. This can be the case if the
Expand All @@ -23,6 +24,11 @@ func InterpolateNetworks(taskEnv *TaskEnv, networks structs.Networks) structs.Ne
// Iterate the copy and perform the interpolation.
for i := range interpolated {
interpolated[i].Hostname = taskEnv.ReplaceEnv(interpolated[i].Hostname)
if interpolated[i].DNS != nil {
interpolated[i].DNS.Servers = taskEnv.ParseAndReplace(interpolated[i].DNS.Servers)
interpolated[i].DNS.Searches = taskEnv.ParseAndReplace(interpolated[i].DNS.Searches)
interpolated[i].DNS.Options = taskEnv.ParseAndReplace(interpolated[i].DNS.Options)
}
}

return interpolated
Expand Down
36 changes: 36 additions & 0 deletions client/taskenv/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,42 @@ func Test_InterpolateNetworks(t *testing.T) {
},
name: "interpolated hostname",
},
{
inputTaskEnv: testEnv,
inputNetworks: structs.Networks{
{
DNS: &structs.DNSConfig{
Servers: []string{"127.0.0.1"},
},
},
},
expectedOutputNetworks: structs.Networks{
{
DNS: &structs.DNSConfig{
Servers: []string{"127.0.0.1"},
},
},
},
name: "non-interpolated dns",
},
{
inputTaskEnv: testEnv,
inputNetworks: structs.Networks{
{
DNS: &structs.DNSConfig{
Servers: []string{"${foo}"},
},
},
},
expectedOutputNetworks: structs.Networks{
{
DNS: &structs.DNSConfig{
Servers: []string{"bar"},
},
},
},
name: "interpolated dns",
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 02004de

Please sign in to comment.