terraform-aws-eks

Production-grade EKS cluster with managed node groups, Fargate, IRSA, add-ons, and EKS Access API
Terraform ≥ 1.5.0 AWS Provider ≥ 5.20.0 Kubernetes 1.25+ Encryption Enabled

Executive Summary

This module provisions a fully managed Amazon EKS cluster with support for multiple managed node groups (ON_DEMAND and SPOT), Fargate profiles for serverless pods, IAM Roles for Service Accounts (IRSA) via OIDC federation, managed add-ons (vpc-cni, coredns, kube-proxy, ebs-csi-driver, pod-identity-agent), and the EKS Access API for fine-grained authentication and authorization. Security hardening includes KMS envelope encryption for secrets, IMDSv2 enforcement, private endpoint access, encrypted EBS volumes, and least-privilege IAM roles per node group. CloudWatch Logs captures all five control plane log types with configurable retention.

Overview

Resources Created
12+
Cluster, Node Groups, Fargate, SGs, IAM, OIDC, KMS, CW Logs, Add-ons, Access Entries
Input Variables
16
cluster_name, cluster_version, vpc_id, subnet_ids, managed_node_groups, etc.
Outputs
17
cluster_id, cluster_endpoint, oidc_provider_arn, node_group_arns, kms_key_arn, etc.
Submodules
3
node-group, fargate-profile, irsa

Architecture Diagram

EKS Control Plane
API Server (Multi-AZ)
OIDC Provider
IRSA
KMS Key
Envelope Encryption
Access Entries
AuthN / AuthZ
System Nodes
ON_DEMAND
App Nodes
ON_DEMAND
Spot Nodes
Cost-Optimized
GPU Nodes
g5.2xlarge
Fargate
Serverless Pods
vpc-cni
coredns
kube-proxy
ebs-csi-driver
pod-identity-agent
Cluster SG
API Access
Node SG
Workers
CloudWatch Logs
5 Log Types

Component Breakdown

EKS Cluster

  • aws_eks_cluster with configurable K8s version (1.25+)
  • Private + public endpoint access control
  • API_AND_CONFIG_MAP authentication mode
  • Envelope encryption for secrets via KMS
  • All 5 control plane log types enabled by default

Managed Node Groups

  • for_each driven -- deploy any number of groups
  • Launch templates with IMDSv2, encrypted EBS (gp3)
  • ON_DEMAND or SPOT capacity types
  • AL2, AL2023, Bottlerocket, GPU AMI types
  • Labels, taints, per-group IAM roles

Fargate Profiles

  • Namespace-based pod selectors with label matching
  • Dedicated pod execution IAM role
  • Custom subnet placement support

Add-ons & Access

  • Managed add-ons: vpc-cni, coredns, kube-proxy, ebs-csi, pod-identity
  • OVERWRITE / NONE / PRESERVE conflict resolution
  • EKS Access Entries with policy associations
  • Namespace-scoped or cluster-scoped access

Data Flow

  1. Clients authenticate via EKS Access API or kubeconfig (OIDC/IAM)
  2. API requests hit the EKS Control Plane through private or public endpoint
  3. Control plane communicates with worker nodes via ENIs in control plane subnets
  4. Node groups launch EC2 instances via launch templates in private subnets
  5. Pods use IRSA for per-service-account AWS credentials via STS AssumeRoleWithWebIdentity
  6. Kubernetes secrets are encrypted at rest using KMS envelope encryption
  7. Control plane logs stream to CloudWatch Log Group with configurable retention

Security Controls

ControlImplementationDefault
Endpoint AccessPrivate-only API endpointprivate=true, public=false
Secrets EncryptionKMS envelope encryptionenable_cluster_encryption=true
IMDSv2Launch template enforces http_tokens=requiredAlways enforced
EBS EncryptionKMS-encrypted gp3 volumesencrypted=true
IAM IsolationPer-node-group IAM roles, Fargate execution roleLeast-privilege
IRSAOIDC provider for pod-level IAMenable_irsa=true
NetworkCluster SG (API) + Node SG (workers)Restricted ingress
Audit LoggingAll 5 control plane log types90-day retention

Industry Adaptation

Financial Services

  • Enable KMS encryption + 365-day log retention
  • Private endpoint only, no public access
  • Dedicated system node group with taints
  • Access Entries for RBAC compliance

Healthcare / HIPAA

  • Customer-managed KMS keys for audit trail
  • EBS encryption on all volumes
  • VPC-isolated control plane subnets
  • IMDSv2 enforcement prevents credential exfiltration

SaaS / Multi-Tenant

  • Spot node groups for cost optimization
  • Fargate profiles for tenant isolation
  • Namespace-scoped access policies
  • Multiple add-ons for platform services

Production Readiness Checklist

Configuration Reference

Key Inputs

VariableTypeDefaultDescription
cluster_namestring--Name of the EKS cluster (required)
cluster_versionstring1.29Kubernetes version
vpc_idstring--VPC for deployment
subnet_idslist(string)--Worker node subnets (min 2)
managed_node_groupsmap(object){}Node group configs with instance types, scaling, taints
fargate_profilesmap(object){}Fargate profile selectors
cluster_addonsmap(object){}EKS managed add-ons
enable_cluster_encryptionbooltrueKMS envelope encryption
enable_irsabooltrueOIDC provider for IRSA
access_entriesmap(object){}EKS Access API entries

Key Outputs

OutputDescription
cluster_endpointAPI server endpoint URL
cluster_certificate_authority_dataBase64 cluster CA cert
oidc_provider_arnOIDC provider ARN for IRSA
node_group_arnsMap of node group ARNs
cluster_security_group_idCluster SG ID
kms_key_arnEncryption key ARN

Deployment

# Initialize
terraform init

# Plan
terraform plan -var-file="production.tfvars"

# Apply
terraform apply -var-file="production.tfvars"

# Configure kubectl
aws eks update-kubeconfig --name <cluster_name> --region <region>

# Verify
kubectl get nodes
kubectl get pods -A

Links & References