DEV Community

Cover image for Terraform + Helm = ❤️
Lucas de Souza
Lucas de Souza

Posted on

Terraform + Helm = ❤️

If you ever tried to manage IaC with Terraform you might end up with “Well, the cloud resources are fine, but how am I going to deal with my Kubernetes cluster???”

In this post, I want to share a simple and functional example of how you can integrate Helm with Terraform using the best of each tool.

The setup of this integration became much easier after Helm v3 was released. Now, you can simply pass your Kubernetes credentials to the Helm Provider and start deploying your charts using Terraform!

provider "helm" {
  kubernetes {
    config_path = "/path/to/kube_cluster.yaml"

You can now deploy Charts using the helm_release resource 🎉.

resource "helm_release" "example" {
  name       = "my-redis-release"
  repository = "" 
  chart      = "redis"
  version    = "6.0.1"

  values = [

  set {
    name  = "cluster.enabled"
    value = "true"

  set {
    name  = "metrics.enabled"
    value = "true"

  set_string {
    name  = "service.annotations.prometheus\\.io/port"
    value = "9127"

Ok, that's fine Lucas, but you have basically shown the Helm provider page... Am I wasting my time here?


In this post, I want to deal with all this excessive set {} parameters in the helm_relase resource. There must be an easier way to manage these variables.


Actually, the tutorial has already shown us how! We can use the values parameter and pass all our variables in a YAML format.

values = [

Instead of using the file function, we can also pass in EOF format:



Okay, okay, I'm sorry! I'm getting into the point, wait a little longer!


In terraform, we can create dynamic templates using the templatefile function. Combe this function with the values parameter in the helm_release resource and we get a lot of flexibility!

The templatefile function has a slite different syntax than Terraform, but you can easily adapt to it.

An example would be:


%{ for addr in ip_addrs ~}
backend ${addr}:${port}
%{ endfor ~}

And to render this template:

templatefile("${path.module}/backends.tmpl", { port = 8080, ip_addrs = ["", ""] })

Giving the output:


And yes, we can also use if statements if you wondered.

We can use all this flexibility right into the values parameter, and here is an example of how to create a dynamic values.yaml:

Templatefile also accept terraform objects making our life easier

If you want to follow the complete example:


In my next post, I'll explain in more detail about this project and how it can help eks clusters running out IPs address.

Thank you for your reading,

Stay safe; stay well.


Top comments (6)

amaurybsouza profile image
Amaury Borges Souza

Nice article, congrats Lucas!

japm94 profile image
Júlio Pedrosa

Parabéns mano, muito bom!!!

jhonatancmorais profile image
Jhonatan Morais

Thanks for sharing!!

souzaxx profile image
Lucas de Souza

Yes! Sorry for that!

I'm finishing the post right now!

smartinov profile image
Stefan Martinov

Great post! Love the memes!