Kubernetes clusters and the Kubernetes and Helm providers

Advanced · 19 min

Create a managed cluster, then configure the kubernetes and helm providers against it without the chicken-and-egg trap, including Helm provider 3's new syntax.

Before thisA VPC on AWSProvider configuration, aliases and multi-region

Anais Urlichs · 19 min

Kubernetes clusters and the Kubernetes and Helm providers

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Anais UrlichsReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Creating a cluster and deploying onto it are two jobs; the kubernetes and helm providers need cluster credentials that do not exist on the first run.
  • The Kubernetes provider docs say the most reliable setup manages the cluster and its Kubernetes resources with separate apply operations, passing values through data sources.
  • Use an exec plugin for short-lived EKS tokens, and do not mix exec with token or client_certificate attributes.
  • Helm provider 3 turned the kubernetes and registry blocks into nested objects and set into a list of objects; videos before 2025 show the old block syntax.

Two jobs that look like one

“Terraform a Kubernetes cluster” sounds like one task. It is two, and they behave differently. The first is creating the cluster: a managed control plane, node capacity, networking and IAM, all in your cloud provider’s API. The second is putting things on it: namespaces, a Helm chart for the ingress controller, a deployment. That uses the Kubernetes API of the cluster you just made.

The trap is that the second job’s provider needs the first job’s output. The kubernetes and helm providers must be configured with a cluster endpoint and credentials, and on the first run, those do not exist yet. How Terraform handles that, and how the official docs tell you to avoid it, is the main thing in this lesson.

Job one: the cluster

On AWS that is EKS, and the pieces are a control plane, node groups or Karpenter, and the VPC from the earlier lesson with subnets tagged so the load balancer controller can find them. Few people write this from scratch. The registry’s terraform-aws-modules/eks/aws module, version 21.30.2 published 17 November 2026 when I looked, declares 108 inputs and 41 outputs, none required, and ships seven submodules including managed node groups, Fargate profiles and Karpenter. It depends on the aws, time and tls providers. I fetched all of this from the registry API with curl, and I have not run the module.

Whatever you choose, treat the cluster as a layer with its own state. It changes rarely, creating it takes many minutes, and a bad plan against it is expensive. The GKE and AKS equivalents are in the last lesson of this group.

Job two: the providers

Once the cluster exists, two providers work inside it:

  • kubernetes manages Kubernetes objects as resources: namespaces, config maps, deployments, service accounts.
  • helm installs charts, with helm_release as the resource.

Which is better for application workloads? For a fixed set of platform add-ons, such as ingress, a metrics stack or cert-manager, a Helm release is the normal way. For application deployments, many teams prefer to leave Terraform out and use GitOps tools (see the devops lesson on Argo CD and Flux), because Terraform’s plan-apply cycle is slow and awkward for things that change daily. A common split is Terraform for the cluster and the bootstrap add-ons, including the GitOps controller, and the controller for everything else.

The chicken and the egg

The Kubernetes provider’s own docs address the problem. Under “Stacking with managed Kubernetes cluster resources”, they say the most reliable way to configure the provider is to ensure the cluster itself and the Kubernetes resources can be managed with separate apply operations, with data sources used to convey values between the two stages. Two states, two applies, two directories.

You can put both in one configuration, with provider settings taken from the cluster resource’s attributes. It works on a good day. It fails in a few ways I know of, though I did not reproduce them here: on a first plan the endpoint is unknown, so the provider cannot connect to read existing objects; if the cluster has to be replaced, the provider is pointing at a cluster that is about to vanish; and a destroy that removes the cluster first strands the objects inside it. Splitting avoids all three. In the split layout, the second configuration reads the cluster by name with a data source, which also makes the dependency visible.

Credentials expire too. The docs show an exec plugin for short-lived tokens, in their EKS example:

provider "kubernetes" {
  host                   = var.cluster_endpoint
  cluster_ca_certificate = base64decode(var.cluster_ca_cert)
  exec {
    api_version = "client.authentication.k8s.io/v1"
    args        = ["eks", "get-token", "--cluster-name", var.cluster_name]
    command     = "aws"
  }
}

That is copied from the Kubernetes provider’s documentation. I did not run it. The docs also warn not to mix exec blocks with other credential attributes such as token or client_certificate, since which credential would be used is undefined. The exec call means your CI role needs permission to get an EKS token, which ties back to OIDC from CI.

The helm provider changed shape

Here is something videos older than 2025 will get wrong. Helm provider version 3 moved to the Terraform Plugin Framework, and the upgrade guide says that blocks such as kubernetes and registry are now nested objects, and that set, set_list and set_sensitive on helm_release are now lists of objects instead of blocks. When I checked the registry on 28 November 2026, the helm provider was at 3.3.0, published 2 September 2026, and kubernetes at 3.6.0, published 27 November. In the Helm provider’s current docs:

provider "helm" {
  kubernetes = {
    config_path = "~/.kube/config"
  }
}

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"
    }
  ]
}

That is the shape from the provider’s own index page, which I read on GitHub, not code I ran. A video that shows kubernetes { ... } as a block inside provider "helm" and set { name = ... } blocks is describing version 2. The upgrade guide says the new provider uses Plugin Protocol Version 6, compatible with Terraform 1.0 and above. The old syntax belongs to the 2.x line, so choose a version on purpose. This is another reason the lock file and constraints matter.

Some habits that save you

  • Pin chart versions with version = on helm_release. Otherwise a new chart release changes your cluster on the next apply.
  • Mark helm_release values from secrets as sensitive and keep the secrets out of state where you can, using ephemeral values.
  • Use terraform state list on the Kubernetes layer after the first apply. If it is empty or enormous, your scope is wrong.
  • Keep CRDs and the resources that use them in separate applies. A kubernetes_manifest for a custom resource needs its definition present at plan time.

About the video

The embed is Anais Urlichs’ “Learn how to use the Terraform Helm Provider”, 19 minutes 25 seconds, November 2022. Its chapters are an intro, an overview drawing of the Terraform provider model, setting up the resources, Terraform commands, and installing the Trivy operator in the cluster. It was recorded against Helm provider 2.x, so the syntax differs from the 3.x snippets above, and it does not create a cluster, which this lesson covers from the docs instead. It is useful for the idea of a provider talking to a cluster. English was judged from the title, description, channel and its English auto-caption track. I did not watch the whole thing. I found an EKS-with-VPC video from Abhishek.Veeramalla, but it is not embeddable, so it is not in deeper.

Where this fits

Everything here was AWS. The last lesson maps the same shapes onto the other two big clouds: GCP and Azure equivalents.

Check yourself

  1. 01Why does configuring the kubernetes provider from a cluster resource in the same configuration fail on a first plan?

    The cluster endpoint and credentials are unknown until the cluster exists, so the provider cannot connect.

  2. 02What changed in the helm provider between version 2 and 3?

    Blocks such as kubernetes and registry became nested objects, and set, set_list and set_sensitive became lists of objects instead of blocks.

  3. 03Why pin the version of a helm_release chart?

    Otherwise a new chart release changes the cluster on the next apply without any change in your code.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark