If your engineering team is still logging into the AWS Console and manually clicking to set up servers, databases, and Kubernetes clusters, then your company is taking massive, unnecessary risk.
In today's world, doing all work manually is a step down for your business. It is too slow and prone to human error. If you need a scalable AWS Elastic Kubernetes Service (EKS) cluster to run your business applications, you need to manage it like a professional engineering organization. You need Infrastructure as Code (IaC).
Today, we are going to use Terraform to define an entire EKS environment in code and deploy it with a single command.
The Prerequisites
Before applying code, you need three tools installed on your local machine: the AWS CLI, Terraform, and kubectl.
If your local machine is Ubuntu, then run the below command on your terminal.
sudo apt update && sudo apt install git -y sudo snap install aws-cli --classic sudo snap install terraform --classic sudo snap install kubectl --classic
Then verify your installed tools as shown below.
trend@boxgeek:$ aws --version aws-cli/2.35.21 Python/3.14.6 Linux/7.0.0-28-generic exe/x86_64.ubuntu.26 trend@boxgeek:$ terraform --version Terraform v1.15.8 on linux_amd64 trend@boxgeek:$ kubectl version --client Client Version: v1.36.3 Kustomize Version: v5.8.1 trend@boxgeek:~$
Connect to AWS
First, you need to link your local terminal to your AWS account. For that, follow the instructions below.
Log into your AWS Console and search IAM. Go to Users and pick a user with AdministratorAccess. Scroll down and go to the Security credentials tab and click Create access key. Copy your Access Key ID and Secret Access Key, which are required for the process ahead. AWS will never show you that Secret Key again. Treat it like your bank password. Never share it, and absolutely never upload it to GitHub.
Back in your terminal, run the below command to connect your terminal to AWS.
aws configure
These four questions will be asked: AWS Access Key ID, AWS Secret Access Key, Default region name, and Default output format. Paste in your keys when asked. Set your default region to us-east-1 and your output format to json.
If you want to check whether you are successfully connected to AWS, then run the below command, which will show you your Account ID.
aws sts get-caller-identity
Expected Output:
{
"UserId": "ABCDEFGHIJK********",
"Account": "0123456789123",
"Arn": "arn:aws:iam::0123456789123:user/Your_Username"
}
Prep the Terraform code
Run these commands in your terminal to create a new folder and open a text editor.
mkdir eks-test cd eks-test nano main.tf
Paste this specific code into the editor. You can replace yourcompanyname wherever you see it in the code.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
data "aws_availability_zones" "available" {}
# 1. The Network (VPC, Subnets, Routing)
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
name = "yourcompanyname-eks-vpc"
cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
public_subnet_tags = {
"kubernetes.io/role/elb" = 1
}
private_subnet_tags = {
"kubernetes.io/role/internal-elb" = 1
}
}
# 2. The Actual Kubernetes Cluster
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "20.0.0"
#replace your Cluster name
cluster_name = "yourcompanyname-cluster"
cluster_version = "1.30"
cluster_endpoint_public_access = true
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
control_plane_subnet_ids = module.vpc.private_subnets
eks_managed_node_groups = {
standard_node_group = {
min_size = 1
max_size = 3
desired_size = 2
instance_types = ["t3.medium"]
capacity_type = "ON_DEMAND"
}
}
enable_cluster_creator_admin_permissions = true
}
To save it, first press CTRL+X, then press Y. Then press Enter.
Launch It
Now we launch Terraform using the below commands.
terraform init terraform apply
Terraform will spit out a massive list of all the networking rules and servers it is about to build. Type yes and hit Enter.
AWS takes a long time to build Kubernetes control planes. It will take around 12 to 15 minutes. So wait for it.
Verify Your New Cluster
Once Terraform is done, your servers are running in the cloud, but your local computer doesn't know how to talk to them yet. Run this to link them up.
aws eks update-kubeconfig --region us-east-1 --name yourcompanyname-cluster
Now, ask Kubernetes to show you your servers:
kubectl get nodes
You will see two t3.medium nodes sitting in a Ready state. You just deployed a production-ready AWS environment using nothing but code.
The Teardown (For tester)
Running a real EKS cluster is not free in AWS. Leaving this running will cost you about $165 a month (roughly $0.22 per hour).
If you are just testing this out to learn, you need to destroy it right now. To destroy it, run the below command.
terraform destroy
Type yes to confirm. Then wait around 10 minutes. Your AWS account will be exactly as it was before.
Conclusion
Setting up Kubernetes on AWS does not have to involve countless manual clicks and hidden settings. By defining your EKS cluster with Terraform, you've just taken a massive step toward professional, reliable engineering. Now you have infrastructure that is reproducible, auditable, and ready to handle your business application.
Now you have a solid foundation, the next step is actually getting your apps running on it. In our next guide, we will dive into setting up a GitOps pipeline using ArgoCD, so you can deploy your applications just by pushing code to GitHub.