Complete Infrastructure as Code (IaC) solution for deploying a production-ready Amazon EKS (Elastic Kubernetes Service) cluster with Terraform. This project demonstrates DevOps best practices for managing AWS Kubernetes infrastructure including networking, compute, database, and monitoring in a unified, modular manner.
- βοΈ AWS-Native EKS: Amazon EKS managed Kubernetes service with auto-managed control plane
- π Production-Ready Security: Multi-AZ deployment, private networking, encryption at rest and in transit
- π Integrated Monitoring: Prometheus and Grafana for metrics, dashboards, and alerting
- ποΈ Modular Architecture: Reusable, independently deployable modules (networking, compute, database, monitoring)
- π Auto-Scaling: Configurable node groups (2-10 nodes) with automatic scaling
- ποΈ Managed Database: Multi-AZ RDS for persistent application data
- π§ͺ Security Scanning: tfsec, Checkov, and tflint for continuous compliance
- π Quick Deployment: 15-25 minute deployment with included helper scripts
EKS-Terraform-Infrastructure-Setup/
β
βββ π Root Configuration Files
β βββ main.tf # Primary Terraform configuration and provider setup
β βββ variables.tf # All input variables with validation rules
β βββ outputs.tf # Output values for infrastructure endpoints
β βββ terraform.tfvars.example # Example configuration template
β
βββ π modules/ # Reusable Terraform modules
β β
β βββ aws/ # AWS provider modules
β β βββ compute/
β β β βββ main.tf # EKS cluster, launch templates, node groups
β β β βββ variables.tf # Compute module input variables
β β β βββ outputs.tf # Cluster endpoints, names, configurations
β β β
β β βββ networking/
β β β βββ main.tf # VPC, subnets, security groups, NAT gateways
β β β βββ variables.tf # Network configuration variables
β β β βββ outputs.tf # VPC IDs, subnet IDs, endpoint references
β β β
β β βββ database/
β β β βββ main.tf # RDS instances, S3 buckets, data stores
β β β βββ variables.tf # Database configuration and credentials
β β β βββ outputs.tf # RDS endpoints, bucket names, connection strings
β β β
β β βββ monitoring/
β β βββ main.tf # CloudWatch, alarms, log groups
β β βββ variables.tf # Monitoring thresholds and configurations
β β βββ outputs.tf # Log group names, alarm endpoints
β β
β βββ monitoring/ # Cross-cloud monitoring stack
β βββ centralized/
β βββ main.tf # Prometheus, Grafana, ELK stack deployment
β βββ variables.tf # Monitoring stack configuration
β βββ outputs.tf # Dashboard URLs, Prometheus endpoints
β
βββ π docs/ # Comprehensive documentation
β βββ architecture.md # System design, component relationships
β βββ ci-cd-pipeline.md # Step-by-step pipeline instructions
β βββ deployment-guide.md # Step-by-step deployment instructions
β βββ security.md # Security best practices, compliance info
β βββ troubleshooting.md # Common issues and solutions
β
βββ π scripts/ # Helper shell scripts
β βββ init.sh # Initialize Terraform, create workspaces
β βββ deploy.sh # Plan and apply Terraform changes
β βββ destroy.sh # Safely destroy infrastructure
β βββ ensure_backend_bucket.sh # Create/configure S3 state backend
β
βββ π§ Quality & Compliance Configuration
β βββ .tflint.hcl # TFLint configuration for code quality
β βββ .checkov.yml # Checkov security policy checks
β βββ .tfsec.yml # tfsec security scanning rules
β βββ .gitignore # Git ignore patterns
β
βββ π State & Lock Files
β βββ .terraform.lock.hcl # Terraform dependency lock file
β βββ terraform.tfstate* # State files (not committed)
β
βββ π This File
βββ README.md # Project documentation (this file)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AWS MULTI-AZ DEPLOYMENT β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β VPC (CIDR: 10.0.0.0/16) β β
β β ββ Public Subnets (AZ-1, AZ-2, AZ-3) β β
β β β ββ NAT Gateways + Internet Gateway β β
β β ββ Private Subnets (AZ-1, AZ-2, AZ-3) β β
β β β ββ EKS Nodes, RDS, Monitoring β β
β β ββ Security Groups & NACLs β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β EKS Cluster (Kubernetes Control Plane) β β
β β ββ Managed Node Groups (Auto Scaling) β β
β β ββ Prometheus + Grafana (Monitoring) β β
β β ββ CoreDNS, kube-proxy, VPC CNI β β
β β ββ RBAC & Network Policies β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Data Layer β β
β β ββ RDS (PostgreSQL/MySQL) Multi-AZ β β
β β ββ S3 Buckets (Versioning, Encryption) β β
β β ββ AWS Secrets Manager β β
β β ββ DynamoDB (Optional) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Observability & Logging β β
β β ββ CloudWatch Logs & Alarms β β
β β ββ Prometheus Metrics β β
β β ββ Grafana Dashboards β β
β β ββ ELK Stack (Elasticsearch, Logstash, Kibana) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Terraform version and provider requirements (AWS ~> 6.0)
- S3 backend for state management with encryption and locking
- Provider configuration with default tags
- AWS Secrets Manager setup for storing Terraform metadata
| Variable | Type | Purpose | Default |
|---|---|---|---|
project_name |
string | Project identifier for tagging | "AWS-Infra" |
environment |
string | dev, staging, or production | - |
owner_email |
string | Infrastructure owner contact (validated) | - |
alert_email |
string | Alert notification recipient (validated) | - |
aws_region |
string | AWS region for deployment | "us-east-1" |
aws_node_count |
number | EKS worker nodes (2-10) | 6 |
aws_instance_type |
string | EC2 instance type for nodes | "t3.medium" |
enable_monitoring |
bool | Enable Prometheus/Grafana stack | true |
enable_aws |
bool | Enable AWS infrastructure | true |
grafana_admin_password |
string | Grafana password (12+ chars, complex) | - |
aws_db_multi_az |
bool | Multi-AZ RDS deployment | true |
Exposes critical infrastructure endpoints:
- AWS VPC ID and networking configuration
- EKS cluster endpoint and credentials
- RDS database connection strings (sensitive)
- CloudWatch log groups and monitoring URLs
- Grafana, Prometheus, and Kibana dashboards
# Required tools
- Terraform >= 1.13.0
- AWS CLI v2 (configured with credentials)
- kubectl (for Kubernetes interactions)
- Git
# AWS Permissions Required
- S3 (create/manage buckets for state)
- EC2 (create VPC, subnets, security groups)
- EKS (create/manage clusters)
- RDS (create database instances)
- CloudWatch (logs and monitoring)
- IAM (roles and policies)
- SecretsManager (store secrets)# 1. Clone the repository
git clone https://github.com/mchittineni/eks-terraform.git
cd eks-terraform
# 2. Create terraform.tfvars from example
cp terraform.tfvars.example terraform.tfvars
# 3. Edit terraform.tfvars with your configuration
nano terraform.tfvars
# Required configurations:
# - environment: dev, staging, or production
# - owner_email: your@email.com (must be valid)
# - alert_email: alerts@email.com (must be valid)
# - aws_region: AWS region (us-east-1, eu-west-1, etc.)
# - aws_node_count: 2-10 (recommended: 6)
# - grafana_admin_password: 12+ chars, uppercase, lowercase, number, special char
# 4. Configure AWS Credentials into your local
export AWS_ACCESS_KEY_ID="xxxxxxx"
export AWS_SECRET_ACCESS_KEY="xxxxxxx"
export AWS_SESSION_TOKEN="xxxxxxx"
# 5. Ensure backend S3 bucket exists
export AWS_REGION=us-east-1
./scripts/ensure_backend_bucket.sh
# 6. Initialize Terraform
./scripts/init.sh
# 7. Plan deployment
terraform plan -out=tfplan
# 8. Apply configuration
terraform apply tfplanUsing Terraform workspaces to isolate state per environment:
# Deploy to dev environment
./scripts/deploy.sh dev
# Deploy to staging
./scripts/deploy.sh staging
# Deploy to production
./scripts/deploy.sh production
# Destroy an environment
./scripts/destroy.sh dev# Plan only AWS networking module
terraform plan -target=module.aws_networking
# Apply only compute (EKS) changes
terraform apply -target=module.aws_compute
# Destroy only monitoring stack
terraform destroy -target=module.aws_monitoringProvisions AWS VPC infrastructure:
- VPC with configurable CIDR block
- Public/Private subnets across multiple AZs
- Internet Gateway and NAT Gateways
- Route tables and associations
- Security groups with ingress/egress rules
Key Outputs:
vpc_id: VPC identifierprivate_subnet_ids: List of private subnets for EKS nodespublic_subnet_ids: List of public subnets for load balancers
Deploys Kubernetes infrastructure:
- EKS cluster (managed control plane)
- Managed node groups with auto-scaling
- IAM roles for cluster and nodes
- Security group configurations
- OIDC provider for IRSA (IAM Roles for Service Accounts)
Key Outputs:
cluster_endpoint: EKS API endpointcluster_name: Cluster identifiercluster_ca_certificate: Certificate authority
Manages data storage:
- RDS instance (PostgreSQL/MySQL) with Multi-AZ
- Automated backups and encryption
- S3 buckets with versioning and encryption
- Parameter groups and option groups
- Database subnet groups
Key Outputs:
db_endpoint: RDS connection endpointdb_name: Database names3_bucket_name: S3 bucket for application data
CloudWatch and alerting:
- Log groups for application and system logs
- CloudWatch alarms for CPU, memory, disk
- SNS topics for notifications
- Dashboard configuration
Key Outputs:
log_group_name: CloudWatch log groupsns_topic_arn: SNS topic for alerts
Centralized monitoring stack:
- Prometheus server for metrics collection
- Grafana for visualization and dashboards
- ELK stack (Elasticsearch, Logstash, Kibana)
- Pre-configured dashboards and alerts
Key Outputs:
grafana_url: Grafana web interfaceprometheus_url: Prometheus UIkibana_url: Kibana for log analysis
Terraform code quality linter:
tflint --config=.tflint.hcl .Checks:
- Syntax and formatting issues
- AWS best practices (e.g., deprecated resources)
- Security configuration errors
- Unused variables and declarations
Infrastructure security scanning:
checkov -o cli -c .checkov.yml --framework terraform .Validates:
- 80+ AWS security policies (CKV1_AWS_*)
- Encryption at rest and in transit
- IAM least privilege
- Logging and monitoring enablement
- Compliance frameworks (CIS, PCI-DSS, HIPAA)
Terraform security scanning:
tfsec --config-file .tfsec.yml .Detects:
- 64+ AWS security rules (aws001-aws064)
- Unencrypted resources
- Publicly accessible services
- Weak security group rules
- Missing backup and logging
# Format check
terraform fmt -check -recursive
# Validate syntax
terraform validate
# Full quality check (all tools)
make check # or run individually:
tflint --config=.tflint.hcl .
checkov -o cli -c .checkov.yml --framework terraform .
tfsec --config-file .tfsec.yml .Initializes Terraform environment:
./scripts/init.sh
# Actions:
# - Initializes Terraform backend
# - Creates dev, staging, production workspaces
# - Sets default workspace to current environmentPlans and applies infrastructure changes:
./scripts/deploy.sh [environment]
# Example:
./scripts/deploy.sh production
# Actions:
# - Switches to specified workspace
# - Runs terraform plan
# - Prompts for confirmation
# - Applies changes if approvedSafely destroys infrastructure:
./scripts/destroy.sh [environment]
# Example:
./scripts/destroy.sh dev
# Actions:
# - Switches to specified workspace
# - Double-confirms destruction
# - Removes all resources in environmentManages S3 state backend:
export AWS_REGION=us-east-1
./scripts/ensure_backend_bucket.sh
# Actions:
# - Creates S3 bucket if not exists
# - Enables versioning
# - Enables server-side encryption
# - Configures bucket policiesβ Encryption
- S3 server-side encryption (AES-256)
- RDS encryption at rest (AWS KMS)
- TLS for data in transit
- Encrypted EBS volumes
β Access Control
- IAM roles with least privilege
- Security groups with minimal ingress rules
- RBAC in Kubernetes
- VPC endpoints for private access
β Monitoring & Logging
- CloudWatch centralized logging
- Prometheus metrics collection
- Grafana alerts and dashboards
- VPC Flow Logs for network monitoring
β Compliance
- AWS CIS Benchmark alignment
- GDPR-ready data handling
- Encrypted secret storage (Secrets Manager)
- Audit trails via CloudTrail (recommended)
- Never commit secrets - Use Secrets Manager or Parameter Store
- Validate email addresses - Required for owner and alert contacts
- Use strong passwords - RDS credentials auto-generated and stored
- Enable MFA - Recommended for AWS console access
- Review IAM policies - Regularly audit generated roles
- Backup databases - Automated RDS backups enabled
- Monitor logs - Configure CloudWatch alarms
| Component | AWS | Estimate/Month |
|---|---|---|
| VPC + NAT Gateway | - | ~$32 |
| EKS Control Plane | - | $73 |
| EC2 Nodes (3x t3.medium) | - | ~$100 |
| RDS Multi-AZ | - | ~$150 |
| CloudWatch Logs | - | ~$20 |
| S3 Storage | - | ~$5 |
| Total (Dev) | AWS | ~$380 |
| Total (Production) | AWS | ~$1500+ |
Estimates based on us-east-1 region, standard configurations
- Terraform: v1.13+ (IaC framework)
- AWS: Cloud provider for all resources
- Amazon EKS: Managed Kubernetes service
- kubectl: Kubernetes CLI
- Helm: Kubernetes package manager (optional)
- Prometheus: Metrics collection and storage
- Grafana: Metrics visualization and dashboards
- ELK Stack: Elasticsearch (storage), Logstash (processing), Kibana (visualization)
- CloudWatch: AWS native monitoring service
- tfsec: Terraform security scanning
- Checkov: Infrastructure security policies
- tflint: Code quality linting
- AWS Secrets Manager: Secure secret storage
- GitHub Actions: Automation and deployment pipelines
- Git: Version control
Comprehensive guides available in docs/ directory:
- architecture.md: EKS cluster design, AWS networking, monitoring stack architecture
- ci-cd-pipeline.md: GitHub Actions CI/CD workflows, automation, and deployment pipeline setup
- deployment-guide.md: Complete step-by-step deployment instructions with examples
- security.md: Security best practices, encryption, IAM, compliance, and security checklist
- troubleshooting.md: Terraform, Kubernetes, EKS, monitoring, and database troubleshooting
Contributions are welcome! Please:
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Run
terraform fmt -recursivefor formatting - Run
terraform validatefor syntax - Run security scans (tfsec, Checkov, tflint)
- Update documentation
- Add tests for new modules
This project is licensed under the MIT License - see LICENSE file for details.
- Issues: Use GitHub Issues for bug reports and feature requests
- Owner: Manideep Chittineni
- Repository: eks-terraform
- Focus: AWS EKS Infrastructure as Code
- Terraform HashiCorp team for excellent IaC tooling
- AWS for robust cloud infrastructure services
- Open source community for tfsec, Checkov, and other security tools
- Prometheus & Grafana communities for monitoring excellence
Last Updated: December 2025
Terraform Version: >= 1.13.0
AWS Provider: ~> 6.0