Setting up EKS with Terraform and the AWS Load Balancer Controller
An EKS 1.37 cluster in Terraform with the v21 EKS module: a VPC, a managed node group, EKS Pod Identity instead of IRSA, and the AWS Load Balancer Controller turning an Ingress into an ALB. Checked with terraform validate, never applied.
Up to now shorty has lived on a kind cluster on my laptop. kind is great for learning, but nothing outside the laptop can reach it. The next step is a real cluster, and on AWS that means EKS.
In this blog we will write the Terraform for an EKS cluster: a VPC, the cluster, a managed node group, EKS Pod Identity so pods get AWS permissions without access keys, and the AWS Load Balancer Controller so an Ingress turns into an ALB. Level is advanced. You should be comfortable with Terraform modules, remote state and IAM roles and trust policies, and know the Kubernetes basics from the first Kubernetes post.
A word on honesty first. I did not apply this. My blog runs on one t3.small, and an EKS control plane itself costs more per month than that whole box. Everything here went through terraform fmt, terraform init and terraform validate, and the Kubernetes manifest went through a server-side dry run on kind. A plan needs real credentials, so I didn't run it. Treat it as a checked starting point, not something I have run in production.
Versions: Terraform 1.17.1, AWS provider 6.73.0, Helm provider 3.3.0, terraform-aws-modules/eks 21.30.2, terraform-aws-modules/vpc 6.8.0, terraform-aws-modules/eks-pod-identity 2.11.0, EKS Kubernetes 1.37, AWS Load Balancer Controller chart 3.6.3 (app v3.6.3).
The files
versions.tf terraform, providers (aws, helm)
main.tf VPC + EKS cluster + managed node group
lb-controller.tf Pod Identity for the controller + helm_release
shorty-pod-identity.tf an IAM role for shorty's own pods
outputs.tf
k8s/ingress.yaml the Ingress that becomes an ALB
Providers
terraform {
required_version = ">= 1.10"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.59"
}
helm = {
source = "hashicorp/helm"
version = "~> 3.3"
}
}
}
provider "aws" {
region = local.region
}
provider "helm" {
kubernetes = {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
exec = {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
}
}
}
The ~> 6.59 is not random. The EKS module v21.30 says aws >= 6.59 in its own versions.tf, so a lower pin would fail at init. The helm provider gets a short-lived token through aws eks get-token rather than a stored kubeconfig.
The VPC
EKS doesn't need anything special from the VPC, only tags. The Load Balancer Controller finds subnets by them: public subnets for internet-facing ALBs, private ones for internal ones. If you built a VPC by hand in the VPC post, this is the same thing through a module.
locals {
name = "shorty"
region = "ap-south-1"
vpc_cidr = "10.20.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
tags = {
Project = "shorty"
}
}
data "aws_availability_zones" "available" {
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 6.8"
name = local.name
cidr = local.vpc_cidr
azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]
enable_nat_gateway = true
single_nat_gateway = true
public_subnet_tags = {
"kubernetes.io/role/elb" = 1
}
private_subnet_tags = {
"kubernetes.io/role/internal-elb" = 1
}
tags = local.tags
}
The private subnets are /20s on purpose. With the VPC CNI every pod gets a real VPC IP, so small subnets run out of addresses long before they run out of CPU. One NAT gateway is cheaper but it's a single AZ dependency, for production I'd pay for one per AZ.
The cluster and a managed node group
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "~> 21.30"
name = local.name
kubernetes_version = "1.37"
endpoint_public_access = true
endpoint_public_access_cidrs = ["203.0.113.10/32"]
enable_cluster_creator_admin_permissions = true
addons = {
coredns = {}
eks-pod-identity-agent = {
before_compute = true
}
kube-proxy = {}
vpc-cni = {
before_compute = true
}
}
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
eks_managed_node_groups = {
default = {
ami_type = "AL2023_ARM_64_STANDARD"
instance_types = ["t4g.medium"]
min_size = 2
max_size = 4
desired_size = 2
}
}
tags = local.tags
}
If you used v20 of this module before, most argument names changed in v21. I tried the old ones to see what happens, and validate stops right away:
Error: Unsupported argument
on main.tf line 49, in module "eks":
49: cluster_name = local.name
An argument named "cluster_name" is not expected here.
cluster_name is now name, cluster_version is kubernetes_version, cluster_addons is addons, and the cluster_endpoint_* ones lost their prefix. The module's upgrade guide (docs/UPGRADE-21.0.md) has the full list. Two defaults changed too: addons now take the most recent version unless you pin one, and the Karpenter submodule dropped IRSA for Pod Identity. The main module still creates an OIDC provider for IRSA (enable_irsa defaults to true), which you can switch off once everything uses Pod Identity. More on that below.
Two other things I noticed reading the module. Its own example still pins kubernetes_version = "1.33". 1.33 left EKS standard support in July 2026, so copying the example as it is puts you on extended support, which costs extra per cluster hour. 1.37 has been on EKS since 1 October 2026. And before_compute = true on the VPC CNI and the Pod Identity agent makes them install before the nodes join, otherwise the first nodes can come up without pod networking and sit NotReady for a while.
enable_cluster_creator_admin_permissions gives whoever runs terraform apply cluster admin through an EKS access entry. Fine for a first cluster. Later, list your admins in access_entries and stop depending on who happened to run apply.
The node group is two Graviton t4g.medium nodes. Managed node groups mean AWS handles the Auto Scaling group, the AMI and draining during upgrades. You still have to bump the node version after a control plane upgrade, EKS won't do that for you.
Pod Identity, in plain words
Basically, pods need AWS permissions sometimes. The controller below needs to create ALBs. shorty might read config from SSM. The old way was IRSA: an OIDC provider, a role trust policy with the service account in a condition, and an annotation on the service account. It works, but the trust policy has to name every cluster's OIDC URL.
Pod Identity is simpler. An agent runs on each node (that's the eks-pod-identity-agent addon), the role trusts one service principal, pods.eks.amazonaws.com, and an association says "service account X in namespace Y gets role Z". The same role works in any cluster. Here is shorty's role, written out by hand so you can see every piece:
data "aws_iam_policy_document" "pod_identity_trust" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole", "sts:TagSession"]
principals {
type = "Service"
identifiers = ["pods.eks.amazonaws.com"]
}
}
}
resource "aws_iam_role" "shorty" {
name = "shorty-app"
assume_role_policy = data.aws_iam_policy_document.pod_identity_trust.json
tags = local.tags
}
data "aws_caller_identity" "current" {}
data "aws_iam_policy_document" "shorty" {
statement {
actions = ["ssm:GetParameter", "ssm:GetParametersByPath"]
resources = ["arn:aws:ssm:${local.region}:${data.aws_caller_identity.current.account_id}:parameter/shorty/*"]
}
}
resource "aws_iam_role_policy" "shorty" {
name = "read-shorty-params"
role = aws_iam_role.shorty.id
policy = data.aws_iam_policy_document.shorty.json
}
resource "aws_eks_pod_identity_association" "shorty" {
cluster_name = module.eks.cluster_name
namespace = "shorty"
service_account = "shorty"
role_arn = aws_iam_role.shorty.arn
}
sts:TagSession is needed, Pod Identity tags the session with the cluster, namespace and service account names. The AWS SDK for Go v2 picks the credentials up through the default chain, no code changes. The Deployment just has to run as serviceAccountName: shorty.
The AWS Load Balancer Controller
The controller watches Ingress (and Service of type LoadBalancer, and Gateway API objects in v3) and creates ALBs and NLBs to match. Its IAM policy is long. The eks-pod-identity module ships it, so I don't keep a copy:
module "aws_lb_controller_pod_identity" {
source = "terraform-aws-modules/eks-pod-identity/aws"
version = "~> 2.11"
name = "aws-lbc"
attach_aws_lb_controller_policy = true
associations = {
this = {
cluster_name = module.eks.cluster_name
namespace = "kube-system"
service_account = "aws-load-balancer-controller"
}
}
tags = local.tags
}
resource "helm_release" "aws_lb_controller" {
name = "aws-load-balancer-controller"
repository = "https://aws.github.io/eks-charts"
chart = "aws-load-balancer-controller"
version = "3.6.3"
namespace = "kube-system"
set = [
{ name = "clusterName", value = module.eks.cluster_name },
{ name = "region", value = local.region },
{ name = "vpcId", value = module.vpc.vpc_id },
{ name = "serviceAccount.name", value = "aws-load-balancer-controller" },
]
depends_on = [module.aws_lb_controller_pod_identity]
}
Now what happens is, Helm provider 3 changed the syntax. set used to be a repeated block, now it's a list attribute, and kubernetes in the provider is an attribute too. Old snippets from blog posts fail like this:
Error: Unsupported block type
on lb-controller.tf line 27, in resource "helm_release" "aws_lb_controller":
27: set {
Blocks of type "set" are not expected here. Did you mean to define argument
"set"? If so, use the equals sign to assign it a value.
At least error message tells you the fix.
Should Terraform install Helm charts at all? Opinions differ. I'm fine with it for cluster plumbing that has AWS pieces tied to it, like this controller and its role. Apps like shorty I'd keep out of Terraform. They change daily and that's a job for a deploy pipeline or GitOps.
An ALB for shorty
With the controller running, this Ingress becomes an internet-facing ALB with HTTPS:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: shorty
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/healthcheck-path: /readyz
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
alb.ingress.kubernetes.io/ssl-redirect: "443"
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-south-1:111122223333:certificate/00000000-0000-0000-0000-000000000000
spec:
ingressClassName: alb
rules:
- host: sho.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: shorty
port:
number: 80
target-type: ip sends traffic straight to pod IPs, skipping the NodePort hop. The health check uses /readyz, the same endpoint the readiness probe uses, so the ALB and Kubernetes agree on which pods are good. The certificate comes from ACM, so there's no cert-manager here, ACM renews it for you.
In the Gateway API post I said to prefer Gateway API over Ingress. That still holds, and the controller has supported Gateway API for ALBs since v3.0. I used Ingress here because it needs no extra CRDs and I could check it on kind (kubectl apply --dry-run=server accepted it). Moving to a Gateway and an HTTPRoute later is a small change.
Running it
terraform fmt -recursive
terraform init
terraform validate
terraform plan -out tfplan
terraform apply tfplan
aws eks update-kubeconfig --region ap-south-1 --name shorty
kubectl get nodes
kubectl -n kube-system get deploy aws-load-balancer-controller
On my side it stopped at validate:
Success! The configuration is valid.
init pulled the three modules plus terraform-aws-modules/kms 4.0.0 (the EKS module uses it to encrypt Secrets), and six providers: aws, helm, tls, time, cloudinit and null. It's a lot of moving parts for "a cluster", which is honestly the main reason I still put small apps on ECS behind an ALB. For one or two services, ECS is less to look after.
When you are done, terraform destroy. But delete the Ingress first. The ALB was made by the controller, not by Terraform, so if the controller goes away first the ALB stays behind and blocks the VPC from being deleted.