How to install Amazon EKS with Terraform: VPC, node group, add-ons, access entries, and Auto Mode
A complete Terraform project for EKS 1.37 with the terraform-aws-modules/vpc 6.8.0 and eks 21.30.2 modules (v21 input names), a managed node group, add-ons, access entries, the Auto Mode variant, update-kubeconfig, and destroy.
Kubernetes$ aws eks update-kubeconfig --region us-east-1 --name demo-eks▍Creating an EKS cluster in the console takes a few clicks, but recreating it exactly in another account or Region is another story. With Terraform and the community terraform-aws-modules modules, the whole cluster (network, control plane, nodes, add-ons, and permissions) becomes reviewable code. This guide builds a complete project for EKS with Kubernetes 1.37, using the VPC module 6.8.0 and the EKS module 21.30.2. Version 21 renamed almost every input, and many examples online still use the old names.
What we will build
| Component | Resource | Note |
|---|---|---|
| Network | VPC with 3 private and 3 public subnets | A single NAT gateway (saves money in dev) |
| Control plane | EKS 1.37 | Public endpoint, authentication through access entries only |
| Nodes | Managed node group with AL2023 | 2 to 4 m6i.large instances |
| Add-ons | coredns, kube-proxy, vpc-cni, eks-pod-identity-agent | Versions managed by AWS |
| Access | Access entries | Admin for whoever runs Terraform, read-only for a team |
If you want to understand the alternatives to EKS (local kind, kubeadm on VMs, AKS, GKE), read how to install Kubernetes with Terraform first.
Prerequisites
- Terraform 1.5.7 or newer (the minimum the EKS 21.x module requires) and AWS CLI v2.
- AWS credentials allowed to create VPC, IAM, EKS, and EC2 resources.
kubectlwithin ±1 minor of the cluster version, which is the supported skew policy.
Project layout:
eks/
├── versions.tf # Terraform and the AWS provider
├── variables.tf # Region and cluster name
├── vpc.tf # VPC module 6.8.0
├── eks.tf # EKS module 21.30.2
└── outputs.tf # name, endpoint, and kubeconfig command
Provider and variables
# versions.tf
terraform {
required_version = ">= 1.5.7"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.74"
}
}
}
provider "aws" {
region = var.region
}
# variables.tf
variable "region" {
type = string
default = "us-east-1"
}
variable "cluster_name" {
type = string
default = "demo-eks"
}
The EKS 21.30.2 module requires AWS provider 6.59 or newer. With ~> 6.74, the lock file resolved to 6.74.0 in our test.
The VPC
# vpc.tf
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.0"
name = "${var.cluster_name}-vpc"
cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
private_subnets = ["10.0.0.0/19", "10.0.32.0/19", "10.0.64.0/19"]
public_subnets = ["10.0.96.0/22", "10.0.100.0/22", "10.0.104.0/22"]
enable_nat_gateway = true
single_nat_gateway = true # dev only: one NAT gateway for all AZs
public_subnet_tags = { "kubernetes.io/role/elb" = 1 }
private_subnet_tags = { "kubernetes.io/role/internal-elb" = 1 }
}
The private subnets are large (/19) on purpose: with the VPC CNI, every pod gets a VPC IP address, and small subnets run out fast. The kubernetes.io/role/elb and kubernetes.io/role/internal-elb tags tell the AWS Load Balancer Controller where to create public and internal load balancers. In production, replace single_nat_gateway with one NAT gateway per AZ.
The EKS cluster
# eks.tf
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "21.30.2"
name = var.cluster_name
kubernetes_version = "1.37"
endpoint_public_access = true
enable_cluster_creator_admin_permissions = true
authentication_mode = "API"
upgrade_policy = {
support_type = "STANDARD"
}
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
addons = {
coredns = {}
kube-proxy = {}
vpc-cni = { before_compute = true }
eks-pod-identity-agent = { before_compute = true }
}
eks_managed_node_groups = {
general = {
ami_type = "AL2023_x86_64_STANDARD"
instance_types = ["m6i.large"]
min_size = 2
max_size = 4
desired_size = 2
update_config = {
max_unavailable_percentage = 33
}
}
}
access_entries = {
devs = {
principal_arn = "arn:aws:iam::111122223333:role/devs"
policy_associations = {
view = {
policy_arn = "arn:aws:eks::aws:cluster-access-policy/AmazonEKSViewPolicy"
access_scope = {
type = "namespace"
namespaces = ["apps"]
}
}
}
}
}
tags = {
Environment = "dev"
Terraform = "true"
}
}
The v21 names
Version 21 dropped the cluster_ prefix from most inputs. We checked every input above against the variables.tf of module 21.30.2:
| v20 (old) | v21 |
|---|---|
cluster_name |
name |
cluster_version |
kubernetes_version |
cluster_endpoint_public_access |
endpoint_public_access |
cluster_addons |
addons |
cluster_compute_config |
compute_config |
cluster_upgrade_policy |
upgrade_policy |
Watch out for changed defaults: in v21, endpoint_public_access defaults to false. Without it, you can only reach the API from inside the VPC. In production, prefer keeping the endpoint private and reaching it through a VPN or a bastion.
Managed node group
The node group uses AL2023_x86_64_STANDARD, which is already the v21 default. It lives in the private subnets, and AWS Auto Scaling keeps it between min_size and max_size. The update_config with max_unavailable_percentage = 33 controls how many nodes are replaced at a time during upgrades. These updates respect your applications’ PodDisruptionBudgets.
Add-ons
The addons block installs EKS managed add-ons. In v21, most_recent defaults to true, so each add-on gets the latest version compatible with 1.37. before_compute = true on vpc-cni and eks-pod-identity-agent creates those two before the nodes, so pods don’t come up without networking.
EKS Pod Identity is the recommended way today to give pods AWS permissions. It needs no OIDC provider, and the same role can be reused across clusters. IRSA is still needed on Fargate and on Windows nodes, which Pod Identity doesn’t support.
Access entries
The aws-auth ConfigMap is deprecated, according to the EKS documentation itself. The current way to grant cluster access is access entries, which you manage through the EKS API and Terraform:
authentication_mode = "API"turns aws-auth off for good. The module default isAPI_AND_CONFIG_MAP, which is useful during migrations.enable_cluster_creator_admin_permissions = truecreates an admin access entry for the identity running Terraform. Without it, you can end up with a cluster you can’t get into.- Each item in
access_entriesbinds an IAM principal to a managed policy, such asAmazonEKSViewPolicyorAmazonEKSClusterAdminPolicy, across the whole cluster or in specific namespaces. You can also usekubernetes_groupswith your own RBAC.
Finally, upgrade_policy with support_type = "STANDARD" keeps the cluster out of extended support, which is the default behavior (EXTENDED) and costs extra. With STANDARD, EKS automatically upgrades the control plane when standard support, which lasts 14 months, ends. Plan your upgrades before then (see how to upgrade a Kubernetes cluster).
Variant: EKS Auto Mode
In Auto Mode, AWS manages the nodes (based on Karpenter) and components such as CoreDNS, pod networking, the EBS CSI driver, and load balancers. You don’t declare node groups and you don’t need the Pod Identity agent. Nodes use immutable Bottlerocket-based AMIs, with no SSH and a maximum lifetime of 21 days. The eks.tf becomes:
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "21.30.2"
name = var.cluster_name
kubernetes_version = "1.37"
endpoint_public_access = true
enable_cluster_creator_admin_permissions = true
authentication_mode = "API"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
# EKS Auto Mode: AWS manages the nodes and the core components
compute_config = {
enabled = true
node_pools = ["general-purpose", "system"]
}
tags = {
Environment = "dev"
Terraform = "true"
}
}
We dropped the addons block because Auto Mode already covers those components. Check the current docs for which add-ons still make sense in your case. The module README documents one trap: to disable Auto Mode, you must apply compute_config = { enabled = false } explicitly. Deleting the block doesn’t turn it off.
Validating without spending anything
Before any apply, validate the syntax and input names without touching AWS:
terraform init -backend=false
terraform validate
terraform fmt -check
Both variants in this article passed those three commands with module 21.30.2, VPC module 6.8.0, and AWS provider 6.74.0. We did not run plan or apply against an AWS account. validate checks input types and names, but not quotas, IAM permissions, or instance availability in the Region.
Applying and connecting to the cluster
# outputs.tf
output "cluster_name" {
value = module.eks.cluster_name
}
output "cluster_endpoint" {
value = module.eks.cluster_endpoint
}
output "configure_kubectl" {
value = "aws eks update-kubeconfig --region ${var.region} --name ${module.eks.cluster_name}"
}
terraform plan -out tfplan
terraform apply tfplan # the control plane usually takes a few minutes
aws eks update-kubeconfig --region us-east-1 --name demo-eks
kubectl get nodes
kubectl get pods -n kube-system
update-kubeconfig adds a context to ~/.kube/config that asks the AWS CLI for a token on every call. Use --alias to give the context a short name. If kubectl answers Unauthorized, check whether your CLI identity is the one that created the cluster, or whether it has an access entry. For everyday commands, see essential kubectl commands.
Costs and destroy
This project costs money from the first minute. The EKS control plane is billed per hour, and the NAT gateway is billed per hour and per GB processed. On top of that come the EC2 instances, EBS volumes, and any load balancers that controllers create. Extended support costs more than standard support. Check the AWS pricing page before you apply and set up a budget alert. To cut spending on forgotten leftovers, see FinOps on AWS.
To tear it all down:
# 1. find what controllers created outside Terraform
kubectl get svc -A --field-selector spec.type=LoadBalancer
kubectl get ingress -A
kubectl get pvc -A
# 2. delete those resources (or the releases and Applications that created them)
# 3. only then destroy the infrastructure
terraform destroy
Load balancers and volumes created by controllers inside the cluster are not in the Terraform state. If they are left behind, the VPC destroy can fail on dependencies, and they keep getting billed.
Checklist
- Modules pinned to
vpc 6.8.0andeks 21.30.2, using v21 input names -
terraform validateandfmt -checkin CI before any apply -
authentication_mode = "API"and access through access entries, no aws-auth - Managed add-ons with
before_computeon vpc-cni and the Pod Identity agent -
upgrade_policychosen deliberately (STANDARD or EXTENDED) - Budget alert in place, and load balancers and volumes removed before
destroy
An EKS cluster in Terraform is a cluster you can recreate, review in a pull request, and destroy without fear.