I'm trying to build up a Helm chart for nginx with Terraform. I created an additional values.yaml file with the following content:
allowableIPs: "{{ .Values.allowableIPs }}"
The Terraform code to fill in the information is like, yes, should have thought of another name for the IP addresses:
variable "allowable_ips" {
type = list(string)
default = []
}
resource "helm_release" "nginx" {
name = "nginx"
chart = "${path.module}/nginx"
namespace = "ns-rebotics"
force_update = false
recreate_pods = true
create_namespace = true
set {
name = "allowableIPs"
value = jsonencode(var.allowable_ips)
}
}
and the variable to be passed in, I just typed rather than created via code to limit my possibility for errors. It is in a locals.tf file:
ip_addresses = ["52.24.34.195/32","34.216.251.107/32","183.14.29.54/32","212.112.111.26/32","172.112.148.169/32","52.34.216.69/32","104.2.87.241/32","107.2.155.54/32","100.15.233.56/32"]
When I execute the TF, I get the following error:
Error: failed parsing key "allowableIPs" with value ["52.24.34.195/32","34.216.251.107/32","183.14.29.54/32","212.112.111.26/32","172.112.148.169/32","52.34.216.69/32","104.2.87.241/32","107.2.155.54/32","100.15.233.56/32"], key "107/32"" has no value (cannot end with ,)
with module.client_instance.module.kubecharts.helm_release.nginx, on REB3Modules/container/nginx/v1/nginx.tf line 63, in resource "helm_release" "nginx": 63: resource "helm_release" "nginx" {
The answer provided by @helpinghand is correct, just a small fix for the template file (remove
%):If you don't want to use the templatefile, you can use the following code to apply the required values.
This will format the variable with required format by Helm, that can be set using the Helm CLI: