Terraform + Helm: Set array of environment variables in Terraform

Viewed 3618

I'm stuck trying to set an array of helm properties from my Terraform code. More precisely, I've got the following value I'd like to set through terraform

Helm variable to set

My guess is that I need to do something like this:

set {
  name = "env"
  value = "{ATL_PROXY_NAME: jira.example.com,ATL_PROXY_PORT: 443,ATL_TOMCAT_SCHEME: https}"
}

but I get the following error:

invalid type for io.k8s.api.core.v1.EnvVar: got "string", expected "map"

Thank you!

2 Answers

The value type of env should be an array of objects with the keys (name, value), with terraform we can define the array elements and set their values one by one:

  1. set the value for the key name for the element at index x
  2. set the value for the key value for the element at index x
set {
  name  = "env[0].name"
  value = "ATL_PROXY_NAME"
}
set {
  name  = "env[0].value"
  value = "jira.example.com"
}
set {
  name  = "env[1].name"
  value = "ATL_PROXY_PORT"
}
set {
  name  = "env[1].value"
  value = "443"
}
set {
  name  = "env[2].name"
  value = "ATL_TOMCAT_SCHEME"
}
set {
  name  = "env[2].value"
  value = "https"
}

Cross-referencing the helm_release resource documentation with Helm behavior and Kubernetes manifest syntax, we would expect to construct a set block in the resource with map type within Terraform (as the Kubernetes error message confirms).

The syntax can be fixed like the following:

set {
  name  = "env"
  value = {"ATL_PROXY_NAME" = "jira.example.com", "ATL_PROXY_PORT" = 443, "ATL_TOMCAT_SCHEME" = "https"}
}

and then the Terraform map type will be passed through Helm inputs as the value for the env key within the Kubernetes manifest as expected.

Related