{"id":22402926,"url":"https://github.com/guivin/terraform-helm-example","last_synced_at":"2025-07-31T16:31:16.554Z","repository":{"id":37570343,"uuid":"472711010","full_name":"guivin/terraform-helm-example","owner":"guivin","description":"Deploy Helm charts with Terraform","archived":false,"fork":false,"pushed_at":"2022-03-23T08:11:29.000Z","size":2088,"stargazers_count":4,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-03-05T09:01:32.099Z","etag":null,"topics":["devops","helm","kubernetes","terraform"],"latest_commit_sha":null,"homepage":"https://getbetterdevops.io","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guivin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-22T10:13:11.000Z","updated_at":"2023-03-05T07:27:01.000Z","dependencies_parsed_at":"2022-08-29T06:31:44.297Z","dependency_job_id":null,"html_url":"https://github.com/guivin/terraform-helm-example","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guivin%2Fterraform-helm-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guivin%2Fterraform-helm-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guivin%2Fterraform-helm-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guivin%2Fterraform-helm-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guivin","download_url":"https://codeload.github.com/guivin/terraform-helm-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228267818,"owners_count":17893841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","helm","kubernetes","terraform"],"created_at":"2024-12-05T09:15:40.351Z","updated_at":"2024-12-05T09:15:40.790Z","avatar_url":"https://github.com/guivin.png","language":"HCL","readme":"# [![terraform-helm-example](https://github.com/guivin/terraform-helm-example/actions/workflows/main.yml/badge.svg)](https://github.com/guivin/terraform-helm-example/actions/workflows/main.yml)\n\nThis repository shows how to use Helm with Terraform using the official [Helm provider](https://registry.terraform.io/providers/hashicorp/helm/2.4.1). \n\nThis deploys a monitoring infrastructure with [Grafana](https://grafana.com/) \u0026 [Prometheus](https://prometheus.io/) \nas a concrete example.\n\n## Requirements\n\n* `Helm \u003e= 3.0`\n* `Terraform \u003e= 1.0.0`\n\n## Deployment\n\nClone the project:\n\n```bash\n$ git clone https://github.com/guivin/terraform-helm-example.git\n```\n\nInitialize the Terraform project:\n\n```bash\n$ terraform init\n```\n\nDeploy the Terraform project:\n\n```\n$ terraform apply\n```\n\n## Pass values to Helm charts in Terraform\n\nThere are several ways to pass values to the `helm_release` resource. In this section, we will the different options.\n\n\n### Using a values.yaml file\n\nThe `values.yaml` of the Helm can be templated by Terraform and specified in the values field:\n\n```hcl\nresource \"helm_release\" \"prometheus\" {\n  chart      = \"prometheus\"\n  name       = \"prometheus\"\n  namespace  = var.namespace\n  repository = \"https://prometheus-community.github.io/helm-charts\"\n  version    = \"15.5.3\"\n\n  values = [\n    templatefile(\"${path.module}/templates/prometheus-values.yaml\", {\n      pod_security_enabled             = true\n      server_persistent_volume_enabled = false\n      server_resources_limits_cpu      = \"256m\"\n      server_resources_limits_memory   = \"256Mi\"\n      server_resources_requests_cpu    = \"256m\"\n      server_resources_requests_memory = \"256Mi\"\n    })\n  ]\n}\n```\n\n### Using the set blocks\n\nThe Helm chart values can be customized with `set` blocks:\n\n```hcl\nresource \"helm_release\" \"prometheus\" {\n  chart      = \"prometheus\"\n  name       = \"prometheus\"\n  namespace  = var.namespace\n  repository = \"https://prometheus-community.github.io/helm-charts\"\n  version    = \"15.5.3\"\n\n  set {\n    name  = \"podSecurityPolicy.enabled\"\n    value = true\n  }\n\n  set {\n    name  = \"server.persistentVolume.enabled\"\n    value = false\n  }\n\n  # You can provide a map of value using yamlencode. Don't forget to escape the last element after point in the name\n  set {\n    name  = \"server\\\\.resources\"\n    value = yamlencode({\n      limits   = {\n        cpu    = \"256m\"\n        memory = \"256Mi\"\n      }\n      requests = {\n        cpu    = \"256m\"\n        memory = \"256Mi\"\n      }\n    })\n  }\n}\n```\n\n### Using the values and yamlencode\n\nThe values of the Helm charts can be added directly as map in the `values` field and encoded into YAML:\n```hcl\nresource \"helm_release\" \"prometheus\" {\n  chart      = \"prometheus\"\n  name       = \"prometheus\"\n  namespace  = var.namespace\n  repository = \"https://prometheus-community.github.io/helm-charts\"\n  version    = \"15.5.3\"\n\n  values = [\n    yamlencode({\n      podSecurityPolicy = {\n        enabled = true\n      }\n      server            = {\n        persistentVolume = {\n          enabled = false\n        }\n        resources        = {\n          limits   = {\n            cpu    = \"256m\"\n            memory = \"256Mi\"\n          }\n          requests = {\n            cpu    = \"256m\"\n            memory = \"256Mi\"\n          }\n        }\n      }\n    })\n  ]\n}\n```\n\n## Access Prometheus UI\n\nCreate the port-forward session to the Prometheus server:\n```bash\n$ kubectl port-forward --namespace monitoring svc/prometheus-server 8080:80\n```\n\nGo to [http://localhost:8080](http://localhost:8080) to access the Prometheus UI:\n\n![Prometheus UI](./screenshots/prometheus-screenshot.jpg)\n\n## Access Grafana UI\n\nCreate the port-forward session to Grafana:\n\n```bash\nkubectl port-forward --namespace monitoring svc/grafana 3000:80\n```\n\nGet the Grafana admin username:\n\n```bash\n$ kubectl get secret --namespace monitoring grafana -o jsonpath=\"{.data.admin-user}\" | base64 --decode \n```\n\nGet the Grafana admin password:\n\n```bash\nkubectl get secret --namespace monitoring grafana -o jsonpath=\"{.data.admin-password}\" | base64 --decode\n```\n\nGo to [http://localhost:3000](http://localhost:3000) to access the Grafana UI. Reuse the previous credentials to log in:\n\n![Grafana Login Page](./screenshots/grafana-login-screenshot.jpg)\n\n![Grafana Home Page](./screenshots/grafana-home-screenshot.jpg)\n\n![Grafana Dashboards](./screenshots/grafana-dashboards-screenshot.jpg)\n\n\nThe [Kubernetes API Server dashboard](https://grafana.com/grafana/dashboards/12006) is provisioned in the `values-grafana.yaml` file. \n\nThe dashboard is visible in the Grafana UI:\n![Grafana Kubernetes API Server Dashboard](./screenshots/grafana-kubernetes-apiserver-dashboard-screenshot.jpg)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguivin%2Fterraform-helm-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguivin%2Fterraform-helm-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguivin%2Fterraform-helm-example/lists"}