This project provides Terraform configurations to create and manage an Amazon EKS cluster.
Note: All Terraform commands should be run from the terraform/ directory.
- AWS CLI installed and configured
- Terraform installed
- AWS account with necessary permissions
-
Setup IAM Permissions:
Ensure your AWS IAM user has the following managed policies attached:
AmazonEC2FullAccessAmazonEKSClusterPolicyIAMFullAccessCloudWatchLogsFullAccess
Or create a custom policy with the necessary permissions for EKS, EC2, IAM, and CloudWatch Logs operations.
-
Configure AWS Credentials:
# Copy the environment template cp .env.template .env # Edit .env and fill in your AWS credentials # AWS_ACCESS_KEY_ID=your_key_here # AWS_SECRET_ACCESS_KEY=your_secret_here
-
Load Environment Variables:
# Source the environment variables source ./env.sh
-
Navigate to the terraform directory:
cd terraform -
Load environment variables (if not already loaded):
source ../env.sh -
Initialize Terraform:
terraform init
-
Plan the deployment:
terraform plan
-
Apply the configuration:
terraform apply
This will create:
- VPC with DNS support
- Public subnets (for NAT Gateways and Load Balancers)
- Private subnets (for EKS worker nodes)
- Internet Gateway
- NAT Gateways (one per AZ for high availability)
- EKS cluster with both public and private subnet access
- Managed node group in private subnets (more secure)
To tear down all node groups (including those not managed by Terraform), apply with the node group creation disabled:
-
Navigate to the terraform directory:
cd terraform -
Load environment variables (if not already loaded):
source ../env.sh -
Set the variable:
terraform apply -var="create_node_group=false"
This will delete all existing node groups in the cluster.
To destroy the entire cluster:
cd terraform
source ../env.sh
terraform destroyregion: AWS region (default: us-east-1)cluster_name: Name of the EKS cluster (default: n0sebleed-eks)vpc_cidr: CIDR for VPC (default: 10.0.0.0/16)public_subnet_cidrs: List of public subnet CIDRs (default: ["10.0.1.0/24", "10.0.2.0/24"])private_subnet_cidrs: List of private subnet CIDRs (default: ["10.0.101.0/24", "10.0.102.0/24"])node_group_name: Name of the node groupinstance_types: Instance types for nodesdesired_capacity: Desired number of nodesmin_size: Minimum number of nodesmax_size: Maximum number of nodescreate_node_group: Whether to create the node group (default: true)
cluster_endpoint: EKS cluster endpointcluster_security_group_id: Security group IDvpc_id: VPC IDpublic_subnet_ids: Public subnet IDsprivate_subnet_ids: Private subnet IDsnat_gateway_ids: NAT Gateway IDs