diff --git a/client/taskenv/network.go b/client/taskenv/network.go index 3bbafaa0c11..7d9b2a0f81a 100644 --- a/client/taskenv/network.go +++ b/client/taskenv/network.go @@ -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 @@ -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 diff --git a/client/taskenv/network_test.go b/client/taskenv/network_test.go index 60589b6f1c3..13279257016 100644 --- a/client/taskenv/network_test.go +++ b/client/taskenv/network_test.go @@ -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 {