### Helm Release Examples
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Various examples demonstrating how to deploy Helm releases using different chart sources.
```APIDOC
## Example Usage - Chart Repository
```terraform
resource "helm_release" "example" {
name = "my-redis-release"
repository = "https://charts.bitnami.com/bitnami"
chart = "redis"
version = "6.0.1"
set = [
{
name = "cluster.enabled"
value = "true"
},
{
name = "metrics.enabled"
value = "true"
},
{
name = "service.annotations.prometheus\\.io/port"
value = "9127"
type = "string"
}
]
}
```
## Example Usage - Local Chart
In case a Chart is not available from a repository, a path may be used:
```terraform
resource "helm_release" "example" {
name = "my-local-chart"
chart = "./charts/example"
}
```
## Example Usage - Chart URL
An absolute URL to the .tgz of the Chart may also be used:
```terraform
resource "helm_release" "example" {
name = "redis"
chart = "https://charts.bitnami.com/bitnami/redis-10.7.16.tgz"
}
```
## Example Usage - Chart Repository configured from OCI Registry
Provider supports grabbing charts from an OCI repository:
```terraform
provider "helm" {
kubernetes = {
config_path = "~/.kube/config"
}
registries = [
{
url = "oci://localhost:5000"
username = "username"
password = "password"
}
]
}
resource "helm_release" "example" {
name = "testchart"
namespace = "helm_registry"
repository = "oci://localhost:5000/helm-charts"
version = "1.2.3"
chart = "test-chart"
}
```
## Example Usage - Chart Repository configured using GCS/S3
The provider also supports helm plugins such as GCS and S3 that add S3/GCS helm repositories by using `helm plugin install`
```terraform
# Install GCS plugin
`helm plugin install https://github.com/hayorov/helm-gcs.git`
# Run follow commands to setup GCS repository
# Init a new repository:
# helm gcs init gs://bucket/path
# Add your repository to Helm:
# helm repo add repo-name gs://bucket/path
# Push a chart to your repository:
# helm gcs push chart.tar.gz repo-name
# Update Helm cache:
# helm repo update
# Get your chart:
resource "helm_release" "GCS" {
name = "GCS"
repository = "gs://tf-test-helm-repo/charts"
chart = "chart"
}
```
```terraform
# Install AWS S3 plugin
`helm plugin install https://github.com/hypnoglow/helm-s3.git`
# Run follow commands to setup S3 repository
# Init a new repository:
# helm s3 init s3://my-helm-charts/stable/myapp
# Add your repository to Helm:
# helm repo add stable-myapp s3://my-helm-charts/stable/myapp/
# Push a chart to your repository:
# helm s3 push chart.tar.gz repo-name
# Update Helm cache:
# helm repo update
# Get your chart:
resource "helm_release" "S3" {
name = "S3"
repository = "s3://tf-test-helm-repo/charts"
chart = "chart"
}
```
## Example Usage - Chart Repository configured outside of Terraform
The provider also supports repositories that are added to the local machine outside of Terraform by running `helm repo add`
```terraform
```
--------------------------------
### Install go-changelog Tools
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Install the necessary go-changelog tools for building and managing changelogs. These commands are typically run using 'go install'.
```bash
go install github.com/hashicorp/go-changelog/cmd/changelog-build
go install github.com/hashicorp/go-changelog/cmd/changelog-entry
```
--------------------------------
### Example YAML Configuration
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
A sample YAML structure for Kubernetes annotations.
```yaml
controller:
pod:
annotations:
status.kubernetes.io/restart-on-failure: {"timeout": "30s"}
```
--------------------------------
### Install the provider binary
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/_about/CONTRIBUTING.md
Create the Terraform plugins directory and move the compiled binary into it.
```sh
> mkdir -p ~/.terraform.d/plugins/
> mv terraform-provider-helm ~/.terraform.d/plugins/
```
--------------------------------
### Install GCS Helm Plugin and Deploy Chart
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Install the GCS Helm plugin, set up a GCS repository, and then deploy a chart from it using Terraform. This involves external Helm commands and a Terraform resource.
```shell
# Install GCS plugin
`helm plugin install https://github.com/hayorov/helm-gcs.git`
# Run follow commands to setup GCS repository
# Init a new repository:
# helm gcs init gs://bucket/path
# Add your repository to Helm:
# helm repo add repo-name gs://bucket/path
# Push a chart to your repository:
# helm gcs push chart.tar.gz repo-name
# Update Helm cache:
# helm repo update
# Get your chart:
```
```terraform
resource "helm_release" "GCS" {
name = "GCS"
repository = "gs://tf-test-helm-repo/charts"
chart = "chart"
}
```
--------------------------------
### Install AWS S3 Helm Plugin and Deploy Chart
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Install the AWS S3 Helm plugin, configure an S3 repository, and deploy a chart using Terraform. This requires external Helm commands and a Terraform resource.
```shell
# Install AWS S3 plugin
`helm plugin install https://github.com/hypnoglow/helm-s3.git`
# Run follow commands to setup S3 repository
# Init a new repository:
# helm s3 init s3://my-helm-charts/stable/myapp
# Add your repository to Helm:
# helm repo add stable-myapp s3://my-helm-charts/stable/myapp/
# Push a chart to your repository:
# helm s3 push chart.tar.gz repo-name
# Update Helm cache:
# helm repo update
# Get your chart:
```
```terraform
resource "helm_release" "S3" {
name = "S3"
repository = "s3://tf-test-helm-repo/charts"
chart = "chart"
}
```
--------------------------------
### Install Helm via Docker
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/test-infra/README.md
Installs Helm using a provided shell script that leverages Docker. Ensure the KUBE_DIR, HELM_VERSION, HELM_HOME, and HYPERKUBE_VERSION environment variables are set appropriately for your environment.
```sh
KUBE_DIR=./gke/kubedir HELM_HOME=./helm-home HYPERKUBE_VERSION=v1.11.8 ./install-helm-via-docker.sh
```
--------------------------------
### Run Changelog Build and Entry Commands with Make
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Execute changelog building and entry creation tasks using make commands. This simplifies the process of running the installed go-changelog tools.
```bash
make changelog
make changelog-entry
```
--------------------------------
### Render all chart templates with Helm
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/data-sources/template.md
Use this example to render all templates of a specified Helm chart. It configures the `helm_template` data source with chart details, repository, version, and custom values for both regular and sensitive settings. The output includes the rendered manifests, which are then saved to local files.
```terraform
data "helm_template" "mariadb_instance" {
name = "mariadb-instance"
namespace = "default"
repository = "https://charts.helm.sh/stable"
chart = "mariadb"
version = "7.1.0"
set = [
{
name = "service.port"
value = "13306"
}
]
set_sensitive = [
{
name = "rootUser.password"
value = "s3cr3t!"
}
]
}
resource "local_file" "mariadb_manifests" {
for_each = data.helm_template.mariadb_instance.manifests
filename = "./${each.key}"
content = each.value
}
output "mariadb_instance_manifest" {
value = data.helm_template.mariadb_instance.manifest
}
output "mariadb_instance_manifests" {
value = data.helm_template.mariadb_instance.manifests
}
output "mariadb_instance_notes" {
value = data.helm_template.mariadb_instance.notes
}
```
--------------------------------
### Changelog Entry: Feature
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Example of a changelog entry for a new feature. It uses the 'release-note:feature' tag followed by a user-facing description.
```release-note
```release-note:feature
plugin/nomad: New feature integration
```
```
--------------------------------
### Install Nginx Ingress Controller with Helm Provider
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/README.md
Configures the Helm provider with a local Kubernetes config path and deploys a specific chart from an OCI repository.
```hcl
provider "helm" {
kubernetes = {
config_path = "~/.kube/config"
}
}
resource "helm_release" "nginx_ingress" {
name = "nginx-ingress-controller"
repository = "oci://registry-1.docker.io/bitnamicharts"
chart = "nginx-ingress-controller"
set = [
{
name = "service.type"
value = "ClusterIP"
}
]
}
```
--------------------------------
### Render selected chart templates with Helm
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/data-sources/template.md
This example demonstrates rendering only specific templates from a Helm chart using the `show_only` argument. It's useful when you need to apply only a subset of the chart's resources. The configuration is similar to rendering all templates but includes a list of template paths to include.
```terraform
data "helm_template" "mariadb_instance" {
name = "mariadb-instance"
namespace = "default"
repository = "https://charts.helm.sh/stable"
chart = "mariadb"
version = "7.1.0"
show_only = [
"templates/master-statefulset.yaml",
"templates/master-svc.yaml",
]
set = [
{
name = "service.port"
value = "13306"
}
]
set_sensitive = [
{
name = "rootUser.password"
value = "s3cr3t!"
}
]
}
resource "local_file" "mariadb_manifests" {
for_each = data.helm_template.mariadb_instance.manifests
filename = "./${each.key}"
content = each.value
}
output "mariadb_instance_manifest" {
value = data.helm_template.mariadb_instance.manifest
}
output "mariadb_instance_manifests" {
value = data.helm_template.mariadb_instance.manifests
}
output "mariadb_instance_notes" {
value = data.helm_template.mariadb_instance.notes
}
```
--------------------------------
### Get Application URL with LoadBalancer Service
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/test-chart-v2/templates/NOTES.txt
Use these commands for LoadBalancer service types. Note that it may take a few minutes for the LoadBalancer IP to become available. You can monitor its status with 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "test-chart.fullname" . }}"'.
```bash
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "test-chart.fullname" . }} --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
```
--------------------------------
### Changelog Entries: Multiple Bugs
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Example demonstrating multiple changelog entries for bug fixes. Each entry is distinct and uses the 'release-note:bug' tag.
```release-note
```release-note:bug
plugin/docker: Fix broken code
```
```release-note:bug
plugin/nomad: Fix broken code
```
```release-note:bug
plugin/k8s: Fix broken code
```
```
--------------------------------
### Get Application URL with NodePort Service
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/test-chart-v2/templates/NOTES.txt
Execute these commands when the service type is NodePort to get the application URL. It requires exporting the NodePort and Node IP.
```bash
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "test-chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
```
--------------------------------
### Changelog Entry: Improvement
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Example of a changelog entry for an improvement. It uses the 'release-note:improvement' tag followed by a user-facing description.
```release-note
```release-note:improvement
server: Add new option for configs
```
```
--------------------------------
### Git Commit Message Example
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Example of a git commit message with a specific subject line format. The subject indicates the component being updated (e.g., 'builtin/k8s') and a brief description of the change.
```git
builtin/k8s: Add support for feature Y
This commit adds support for feature Y....
```
--------------------------------
### Changelog Entry: Bug Fix
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Example of a changelog entry for a bug fix. It uses the 'release-note:bug' tag followed by a user-facing description.
```release-note
```release-note:bug
plugin/docker: Fix broken code
```
```
--------------------------------
### Get Application URL for LoadBalancer Service
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/dependency-bar/templates/NOTES.txt
This script fetches the LoadBalancer IP address and constructs the application URL. Note that it may take time for the LoadBalancer IP to become available after deployment.
```bash
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "dependency-bar.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "dependency-bar.fullname" . }} --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
```
--------------------------------
### Changelog Entry: Feature with Long Description
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Example of a feature changelog entry with a long, detailed description including markdown formatting. It uses the 'release-note:feature' tag.
```release-note
```release-note:feature
cli: Lorem ipsum dolor `sit amet`, _consectetur_ adipiscing elit, **sed** do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
```
```
--------------------------------
### Get Application URL with ClusterIP Service
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/test-chart-v2/templates/NOTES.txt
This snippet is for ClusterIP service types. It forwards port 8080 on localhost to the application's port and provides a local URL.
```bash
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "test-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
```
--------------------------------
### Get Application URL for NodePort Service
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/dependency-bar/templates/NOTES.txt
For NodePort services, this script retrieves the NodePort and Node IP to construct the application URL. It assumes a single NodePort is configured.
```bash
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "dependency-bar.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
```
--------------------------------
### Build the provider binary
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/_about/CONTRIBUTING.md
Navigate to the provider directory and execute the build command.
```sh
> cd $GOPATH/src/github.com/hashicorp/terraform-provider-helm
> make build
```
--------------------------------
### Clone the Helm provider repository
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/_about/CONTRIBUTING.md
Create the necessary directory structure and clone the repository into the GOPATH.
```sh
> mkdir -p $GOPATH/src/github.com/terraform-providers
> git clone https://github.com/hashicorp/terraform-provider-helm.git $GOPATH/src/github.com/hashicorp/terraform-provider-helm
```
--------------------------------
### Retrieve Application URL via Helm Template
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/dependency-foo/templates/NOTES.txt
Use this logic within a Helm NOTES.txt file to dynamically display access instructions based on the configured service type.
```helm
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "dependency-foo.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "dependency-foo.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "dependency-foo.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "dependency-foo.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
```
--------------------------------
### Deploy Helm Chart from Repository
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Use this to deploy a Helm chart from a specified repository. Configure release name, repository URL, chart name, and version.
```terraform
resource "helm_release" "example" {
name = "my-redis-release"
repository = "https://charts.bitnami.com/bitnami"
chart = "redis"
version = "6.0.1"
set = [
{
name = "cluster.enabled"
value = "true"
},
{
name = "metrics.enabled"
value = "true"
},
{
name = "service.annotations.prometheus\\.io/port"
value = "9127"
type = "string"
}
]
}
```
--------------------------------
### Kubernetes Configuration Block
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
Settings for connecting to the Kubernetes API.
```APIDOC
## Kubernetes Configuration Block
### Description
Defines how the provider connects to the Kubernetes cluster.
### Parameters
#### Request Body
- **config_path** (string) - Optional - Path to kube config file.
- **host** (string) - Optional - Hostname of the Kubernetes API.
- **username** (string) - Optional - Username for HTTP basic auth.
- **password** (string) - Optional - Password for HTTP basic auth.
- **token** (string) - Optional - Bearer token for authentication.
- **insecure** (boolean) - Optional - Skip TLS certificate verification.
- **client_certificate** (string) - Optional - PEM-encoded client certificate.
- **client_key** (string) - Optional - PEM-encoded client key.
- **cluster_ca_certificate** (string) - Optional - PEM-encoded root CA bundle.
```
--------------------------------
### Initialize and Apply Terraform Configuration
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/test-infra/gke/README.md
Initializes the Terraform environment and applies the configuration with a specific Kubernetes version.
```hcl
terraform init
terraform apply -var=kubernetes_version=1.7.12-gke.1
```
--------------------------------
### Enable Helm Provider Experiments
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
This snippet shows how to enable the `manifest` experiment for the Helm provider, which stores the rendered manifest for `helm_release` to display changes in the plan.
```terraform
provider "helm" {
experiments = {
manifest = true
}
}
```
--------------------------------
### Configure EKS authentication with exec plugin
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
Uses the AWS CLI to fetch authentication tokens for an EKS cluster.
```terraform
provider "helm" {
kubernetes = {
host = var.cluster_endpoint
cluster_ca_certificate = base64decode(var.cluster_ca_cert)
exec = {
api_version = "client.authentication.k8s.io/v1beta1"
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
command = "aws"
}
}
}
```
--------------------------------
### Run Acceptance Tests
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/test-infra/README.md
Executes acceptance tests for the Helm provider. This command requires HELM_HOME and KUBECONFIG environment variables to be set, pointing to the Helm home directory and the Kubernetes configuration file respectively. It uses the 'make testacc' command.
```sh
HELM_HOME=./helm-home KUBECONFIG=./gke/kubedir/config make testacc
```
--------------------------------
### Access Application via Port-Forward for ClusterIP Service
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/dependency-bar/templates/NOTES.txt
For ClusterIP services, this script finds a pod associated with the application and sets up port-forwarding to access it locally. It then provides a local URL.
```bash
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "dependency-bar.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
```
--------------------------------
### Deploy Nginx Ingress Controller using Helm Release
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
This resource deploys the nginx-ingress-controller chart from the Bitnami repository. It demonstrates how to set specific values for the chart, such as the service type.
```terraform
resource "helm_release" "nginx_ingress" {
name = "nginx-ingress-controller"
repository = "https://charts.bitnami.com/bitnami"
chart = "nginx-ingress-controller"
set = [
{
name = "service.type"
value = "ClusterIP"
}
]
}
```
--------------------------------
### Run Acceptance Tests
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/test-infra/gke/README.md
Executes acceptance tests for the repository, with options to filter by test name using regular expressions.
```bash
TESTARGS="-run '^TestAcc'" make testacc
```
```bash
TESTARGS="-run '^TestAccKubernetesPod_'" make testacc
```
--------------------------------
### Helm Template Configuration Migration
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/guides/v3-upgrade-guide.md
Comparison of the legacy SDKv2 block-based configuration and the new Plugin Framework list-based configuration for helm_template.
```hcl
data "helm_template" "example" {
name = "my-release"
chart = "my-chart"
namespace = "my-namespace"
values = ["custom-values.yaml"]
set {
name = "image.tag"
value = "1.2.3"
}
set_list {
name = "allowed.hosts"
value = ["host1", "host2"]
}
set_sensitive {
name = "api.key"
value = "super-secret-key"
}
}
```
```hcl
data "helm_template" "example" {
name = "my-release"
chart = "my-chart"
namespace = "my-namespace"
values = ["custom-values.yaml"]
set = [
{
name = "image.tag"
value = "1.2.3"
}
]
set_list = [
{
name = "allowed.hosts"
value = ["host1", "host2"]
}
]
set_sensitive = [
{
name = "api.key"
value = "super-secret-key"
}
]
}
```
--------------------------------
### Retrieve Application URL via Helm Templates
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/test-chart/templates/NOTES.txt
Use this template logic to output the correct access URL based on the configured service type in values.yaml. Ensure the chart release name and namespace are correctly referenced.
```helm
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "test-chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "test-chart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "test-chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "test-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
```
--------------------------------
### Export Kubernetes and Google Cloud Environment Variables
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/test-infra/gke/README.md
Sets the KUBECONFIG and GOOGLE_ZONE environment variables using Terraform outputs to enable cluster access.
```bash
export KUBECONFIG="$(terraform output kubeconfig_path)"
export GOOGLE_ZONE=$(terraform output google_zone)
```
--------------------------------
### Access ClusterIP Service via Port Forwarding
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/umbrella-chart/templates/NOTES.txt
This snippet is for ClusterIP service types. It finds the pod name and sets up port forwarding to access the application locally.
```bash
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "umbrella-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
```
--------------------------------
### Define a Helm chart resource
Source: https://github.com/hashicorp/terraform-provider-helm/wiki/Home
Use this resource to deploy a Helm chart with specific configuration values.
```hcl
resource "helm_chart" "my_databsase" {
name = "my_databsase"
chart = "stable/mariadb"
value {
name = "mariadbUser"
content = "foo"
}
value {
name = "mariadbPassword"
content = "qux"
}
}
```
--------------------------------
### Helm Release Configuration Parameters
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
A comprehensive list of optional configuration parameters for managing Helm releases via the Terraform Helm provider.
```APIDOC
## Configuration Parameters
### Description
These parameters define the behavior of Helm chart installations, upgrades, and repository interactions within the Terraform Helm provider.
### Parameters
- **atomic** (Boolean) - Optional - If set, installation process purges chart on fail. Defaults to false.
- **cleanup_on_fail** (Boolean) - Optional - Allow deletion of new resources created in this upgrade when upgrade fails. Defaults to false.
- **create_namespace** (Boolean) - Optional - Create the namespace if it does not exist. Defaults to false.
- **dependency_update** (Boolean) - Optional - Run helm dependency update before installing the chart. Defaults to false.
- **description** (String) - Optional - Add a custom description.
- **devel** (Boolean) - Optional - Use chart development versions.
- **disable_crd_hooks** (Boolean) - Optional - Prevent CRD hooks from running.
- **disable_openapi_validation** (Boolean) - Optional - Skip validation of rendered templates against Kubernetes OpenAPI Schema. Defaults to false.
- **disable_webhooks** (Boolean) - Optional - Prevent hooks from running. Defaults to false.
- **force_update** (Boolean) - Optional - Force resource update through delete/recreate if needed. Defaults to false.
- **keyring** (String) - Optional - Location of public keys used for verification.
- **lint** (Boolean) - Optional - Run helm lint when planning. Defaults to false.
- **max_history** (Number) - Optional - Limit the maximum number of revisions saved per release. Defaults to 0.
- **namespace** (String) - Optional - Namespace to install the release into. Defaults to default.
- **pass_credentials** (Boolean) - Optional - Pass credentials to all domains. Defaults to false.
- **recreate_pods** (Boolean) - Optional - Perform pods restart during upgrade/rollback. Defaults to false.
- **render_subchart_notes** (Boolean) - Optional - Render subchart notes along with the parent. Defaults to true.
- **replace** (Boolean) - Optional - Re-use the given name, even if already used. Defaults to false.
- **repository** (String) - Optional - Repository where to locate the requested chart.
- **repository_password** (String) - Optional - Password for HTTP basic authentication.
- **repository_username** (String) - Optional - Username for HTTP basic authentication.
- **reset_values** (Boolean) - Optional - When upgrading, reset the values to the ones built into the chart. Defaults to false.
- **reuse_values** (Boolean) - Optional - When upgrading, reuse the last release's values. Defaults to false.
- **skip_crds** (Boolean) - Optional - If set, no CRDs will be installed. Defaults to false.
- **take_ownership** (Boolean) - Optional - Allows Helm to adopt existing resources. Defaults to false.
- **timeout** (Number) - Optional - Time in seconds to wait for any individual kubernetes operation. Defaults to 300.
- **upgrade_install** (Boolean) - Optional - Equivalent to running 'helm upgrade --install'. Defaults to false.
- **values** (List of String) - Optional - List of values in raw yaml format.
- **verify** (Boolean) - Optional - Verify the package before installing. Defaults to false.
- **version** (String) - Optional - Specify the exact chart version to install.
- **wait** (Boolean) - Optional - Wait until all resources are in a ready state. Defaults to true.
- **wait_for_jobs** (Boolean) - Optional - Wait until all Jobs have been completed. Defaults to false.
```
--------------------------------
### Setting List Values
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Demonstrates how to pass a list of values to a Helm chart variable.
```terraform
set_list = [
{
name = "hashicorp"
value = ["terraform", "nomad", "vault"]
}
]
```
--------------------------------
### Configure static Helm provider credentials
Source: https://github.com/hashicorp/terraform-provider-helm/wiki/Home
Define provider credentials statically to override default configuration file settings.
```hcl
provider "helm" {
kubernetes {
host = "https://104.196.242.174"
username = "ClusterMaster"
password = "MindTheGap"
client_certificate = "${file("~/.kube/client-cert.pem")}"
client_key = "${file("~/.kube/client-key.pem")}"
cluster_ca_certificate = "${file("~/.kube/cluster-ca-cert.pem")}"
}
}
```
--------------------------------
### Deploy Helm Chart from Chart URL
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Deploy a Helm chart directly from a .tgz archive URL. Provide the release name and the absolute URL to the chart archive.
```terraform
resource "helm_release" "example" {
name = "redis"
chart = "https://charts.bitnami.com/bitnami/redis-10.7.16.tgz"
}
```
--------------------------------
### Configure GKE authentication with exec plugin
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
Uses the gke-cloud-auth-plugin to authenticate with a GKE cluster.
```terraform
provider "helm" {
kubernetes = {
host = "https://${data.google_container_cluster.my_cluster.endpoint}"
token = data.google_client_config.provider.access_token
cluster_ca_certificate = base64decode(
data.google_container_cluster.my_cluster.master_auth[0].cluster_ca_certificate,)
exec = {
api_version = "client.authentication.k8s.io/v1beta1"
command = "gke-gcloud-auth-plugin"
}
}
}
```
--------------------------------
### Deploy Helm Chart from Local Path
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Deploy a Helm chart located in a local directory. Specify the release name and the relative or absolute path to the chart.
```terraform
resource "helm_release" "example" {
name = "my-local-chart"
chart = "./charts/example"
}
```
--------------------------------
### Helm Provider Configuration
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
Configuration settings for the Helm provider, including paths, driver settings, and performance tuning.
```APIDOC
## Helm Provider Configuration
### Description
Configures the Helm provider settings for interacting with Helm and Kubernetes.
### Parameters
#### Request Body
- **debug** (boolean) - Optional - Whether Helm is running in Debug mode. Defaults to false.
- **plugins_path** (string) - Optional - Path to the plugins directory.
- **registry_config_path** (string) - Optional - Path to the registry config file.
- **repository_config_path** (string) - Optional - Path to the repository config file.
- **repository_cache** (string) - Optional - Path to the repository cache.
- **helm_driver** (string) - Optional - Backend storage driver (configmap, secret, memory, sql).
- **burst_limit** (number) - Optional - Helm burst limit. Default: 100.
- **qps** (number) - Optional - Queries per second for Kubernetes API communication.
```
--------------------------------
### Generate Ingress URLs
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/crds-chart/templates/NOTES.txt
This snippet generates application URLs when Ingress is enabled, iterating through hosts and paths defined in the values.
```go-template
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- end }}
```
--------------------------------
### Import Helm Release Resource
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Use this command to import an existing Helm Release into your Terraform state. The format requires the namespace and name of the release, separated by a forward slash.
```shell
$ terraform import helm_release.example default/example-name
```
--------------------------------
### Access ClusterIP Service via Port-Forward
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/crds-chart/templates/NOTES.txt
This snippet provides instructions to access a ClusterIP service by port-forwarding. It finds the pod name and then forwards local port 8080 to the pod's port 80.
```bash
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "test-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
```
--------------------------------
### Generate CHANGELOG Entries for Release
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/CHANGELOG_GUIDE.md
Command to generate changelog entries for a release using the changelog-build tool. It specifies the last release tag, entries directory, changelog template, note template, and the current release commit hash.
```bash
changelog-build -last-release v0.5.0 -entries-dir .changelog/ -changelog-template changelog.tmpl -note-template note.tmpl -this-release 86b6b38faa7c69f26f1d4c71e271cd4285daadf9
```
--------------------------------
### Configure Helm Provider with Multiple Kubeconfig Paths
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
Configure the Helm provider to use multiple kubeconfig files. The provider will attempt to load configurations from each specified path, similar to kubectl's behavior.
```terraform
provider "helm" {
kubernetes = {
config_paths = [
"/path/to/config_a.yaml",
"/path/to/config_b.yaml"
]
}
}
```
--------------------------------
### Basic Helm Release Resource
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Defines a basic Helm release resource for a chart.
```terraform
resource "helm_release" "example" {
name = "redis"
chart = "bitnami/redis"
}
```
--------------------------------
### Configure Experiments in Helm Provider
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/guides/v3-upgrade-guide.md
Updates the experiments block to a single nested object attribute.
```hcl
provider "helm" {
experiments {
manifest = true
}
}
```
```hcl
provider "helm" {
experiments = {
manifest = true
}
}
```
--------------------------------
### Registry Configuration Block
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/index.md
Authentication settings for private OCI registries.
```APIDOC
## Registry Configuration Block
### Description
Configures authentication for private OCI registries.
### Parameters
#### Request Body
- **url** (string) - Required - URL to the registry (oci://host:port).
- **username** (string) - Required - Username for registry.
- **password** (string) - Required - Password for registry.
```
--------------------------------
### Configure Kubernetes and Registry in Helm Provider
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/guides/v3-upgrade-guide.md
Updates the provider configuration to use a single nested object for kubernetes and a list for registries.
```hcl
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
registry {
url = "oci://localhost:5000"
username = "username"
password = "password"
}
registry {
url = "oci://private.registry"
username = "username"
password = "password"
}
}
```
```hcl
provider "helm" {
kubernetes = {
config_path = "~/.kube/config"
}
registries = [
{
url = "oci://localhost:5000"
username = "username"
password = "password"
},
{
url = "oci://private.registry"
username = "username"
password = "password"
}
]
}
```
--------------------------------
### Retrieve LoadBalancer Service URL
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/crds-chart/templates/NOTES.txt
This snippet retrieves the application URL for a LoadBalancer service. It fetches the LoadBalancer IP and service port. Note that it may take a few minutes for the LoadBalancer IP to become available.
```bash
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "test-chart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "test-chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}})
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- end }}
```
--------------------------------
### Resource: helm_release
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Defines the desired status of a Helm chart release in a Kubernetes cluster.
```APIDOC
## Resource: helm_release
### Description
A Release is an instance of a chart running in a Kubernetes cluster. The helm_release resource describes the desired status of a chart in a Kubernetes cluster.
### Parameters
#### Required
- **chart** (String) - Required - Chart name to be installed. A path may be used.
- **name** (String) - Required - Release name. The length must not be longer than 53 characters.
```
--------------------------------
### helm_release Resource
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Configuration details for the `helm_release` resource, including read-only attributes and nested schema definitions.
```APIDOC
## helm_release Resource
### Description
Manages a Helm chart release.
### Attributes
#### Read-Only
- `id` (String) The ID of this resource.
- `manifest` (String) The rendered manifest as JSON.
- `resources` (Map of String) Rendered manifests as JSON.
- `metadata` (List of Object) Status of the deployed release. (see [below for nested schema](#nestedatt--metadata))
- `status` (String) Status of the release.
### Nested Schemas
### Nested Schema for `postrender`
Required:
- `binary_path` (String) The command binary path.
Optional:
- `args` (List of String) an argument to the post-renderer (can specify multiple)
### Nested Schema for `set`
Required:
- `name` (String)
Optional:
- `type` (String)
- `value` (String)
### Nested Schema for `set_list`
Required:
- `name` (String)
- `value` (List of String)
### Nested Schema for `set_sensitive`
Required:
- `name` (String)
- `value` (String, Sensitive)
Optional:
- `type` (String)
### Nested Schema for `metadata`
Read-Only:
- `app_version` (String)
- `chart` (String)
- `first_deployed` (Number)
- `last_deployed` (Number)
- `name` (String)
- `namespace` (String)
- `notes` (String)
- `revision` (Number)
- `values` (String)
- `version` (String)
```
--------------------------------
### Setting Complex Values with Escaping
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Demonstrates how to escape special characters in HCL when setting Helm values.
```terraform
set = [
{
name = "grafana.ingress.annotations.alb\\.ingress\\.kubernetes\\.io/group\\.name"
value = "shared-ingress"
}
]
```
--------------------------------
### helm_template Data Source
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/data-sources/template.md
Renders Helm chart templates locally and exposes the rendered manifests.
```APIDOC
## helm_template Data Source
### Description
`helm_template` renders chart templates locally and exposes the rendered manifests in the data source attributes. `helm_template` mimics the functionality of the `helm template` command.
The arguments aim to be identical to the `helm_release` resource.
For further details on the `helm template` command, refer to the [Helm documentation](https://helm.sh/docs/helm/helm_template/).
### Schema
#### Required
- **chart** (String) - Chart name to be installed. A path may be used.
- **name** (String) - Release name.
```
--------------------------------
### Retrieve NodePort Service URL
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/helm/testdata/charts/crds-chart/templates/NOTES.txt
This snippet retrieves the application URL for a NodePort service. It fetches the NodePort and Node IP using kubectl commands.
```bash
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "test-chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- end }}
```
--------------------------------
### Configure helm_release Set Attributes
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/guides/v3-upgrade-guide.md
Updates set, set_list, and set_sensitive to use list of nested objects syntax.
```hcl
resource "helm_release" "nginx_ingress" {
name = "nginx-ingress-controller"
repository = "https://charts.bitnami.com/bitnami"
chart = "nginx-ingress-controller"
set {
name = "service.type"
value = "ClusterIP"
}
set_list {
name = "allowed.hosts"
value = ["host1", "host2"]
}
set_sensitive {
name = "api.key"
value = "super-secret-key"
}
}
```
```hcl
resource "helm_release" "nginx_ingress" {
name = "nginx-ingress-controller"
repository = "https://charts.bitnami.com/bitnami"
chart = "nginx-ingress-controller"
set = [
{
name = "service.type"
value = "ClusterIP"
}
]
set_list = [
{
name = "allowed.hosts"
value = ["host1", "host2"]
}
]
set_sensitive = [
{
name = "api.key"
value = "super-secret-key"
}
]
}
```
--------------------------------
### Configure Helm Provider for OCI Registry
Source: https://github.com/hashicorp/terraform-provider-helm/blob/main/docs/resources/release.md
Configure the Helm provider to use an OCI registry. Specify the Kubernetes config path and registry details including URL, username, and password.
```terraform
provider "helm" {
kubernetes = {
config_path = "~/.kube/config"
}
registries = [
{
url = "oci://localhost:5000"
username = "username"
password = "password"
}
]
}
resource "helm_release" "example" {
name = "testchart"
namespace = "helm_registry"
repository = "oci://localhost:5000/helm-charts"
version = "1.2.3"
chart = "test-chart"
}
```