|
| 1 | +# Terraform EKS Sandbox Configuration |
| 2 | + |
| 3 | +This directory provisions a cost-optimized Amazon EKS sandbox cluster in region `eu-central-1`. |
| 4 | + |
| 5 | +## What this sets up |
| 6 | + |
| 7 | +- A VPC (`10.0.0.0/16`) with: |
| 8 | + - 2 public subnets across the first two availability zones in the selected region |
| 9 | + - 2 private subnets across the first two availability zones in the selected region |
| 10 | + - Internet Gateway |
| 11 | + - Single NAT Gateway (lower cost than one per AZ) |
| 12 | +- IAM roles for EKS control plane and worker nodes |
| 13 | +- EKS cluster (`sandbox-eks`, Kubernetes `1.31`) with public and private API endpoint access |
| 14 | +- One managed node group: |
| 15 | + - Instance type: `t3.medium` |
| 16 | + - Desired/min/max size: `2/1/3` |
| 17 | + - Disk size: `20 GiB` |
| 18 | + - AMI type: `AL2023_x86_64_STANDARD` |
| 19 | +- EKS managed add-ons: `coredns`, `kube-proxy`, `vpc-cni` |
| 20 | +- Local Terraform state (no remote backend configured) |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +- Terraform `>= 1.5` |
| 25 | +- AWS CLI v2 installed |
| 26 | +- AWS identity with permissions to create VPC, IAM, EKS, and EC2 resources in your target account |
| 27 | + |
| 28 | +## AWS authentication (required before `terraform plan` / `terraform apply`) |
| 29 | + |
| 30 | +If you are using `aws login` and your AWS profile uses `login_session`, Terraform may not detect credentials directly. Use a Terraform-specific wrapper profile via `credential_process`. |
| 31 | + |
| 32 | +1. Sign in to your normal AWS login profile: |
| 33 | + |
| 34 | +```bash |
| 35 | +aws login --profile <your-login-profile> |
| 36 | +``` |
| 37 | + |
| 38 | +2. Add a Terraform wrapper profile in `~/.aws/config`: |
| 39 | + |
| 40 | +```ini |
| 41 | +[profile terraform] |
| 42 | +credential_process = aws configure export-credentials --profile <your-login-profile> --format process |
| 43 | +region = eu-central-1 |
| 44 | +``` |
| 45 | + |
| 46 | +3. In the shell where you run Terraform, point tooling at that profile: |
| 47 | + |
| 48 | +```bash |
| 49 | +unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN |
| 50 | +export AWS_PROFILE=terraform |
| 51 | +export AWS_REGION=eu-central-1 |
| 52 | +export AWS_SDK_LOAD_CONFIG=1 |
| 53 | +``` |
| 54 | + |
| 55 | +4. Verify credentials before running Terraform: |
| 56 | + |
| 57 | +```bash |
| 58 | +aws sts get-caller-identity |
| 59 | +``` |
| 60 | + |
| 61 | +> Security note: do not commit `~/.aws/config`, `~/.aws/credentials`, or any copied credential values to git. |
| 62 | +
|
| 63 | +## Usage |
| 64 | + |
| 65 | +```bash |
| 66 | +terraform init |
| 67 | +terraform plan |
| 68 | +terraform apply |
| 69 | +``` |
| 70 | + |
| 71 | +## Configure kubectl |
| 72 | + |
| 73 | +After `terraform apply`, run the command from the Terraform output: |
| 74 | + |
| 75 | +```bash |
| 76 | +terraform output -raw kubeconfig_command |
| 77 | +``` |
| 78 | + |
| 79 | +Then execute the printed command, for example: |
| 80 | + |
| 81 | +```bash |
| 82 | +aws eks update-kubeconfig --region eu-central-1 --name sandbox-eks |
| 83 | +``` |
| 84 | + |
| 85 | +## Estimated cost (rough) |
| 86 | + |
| 87 | +- EKS control plane: **~$0.10/hour** |
| 88 | +- 2x `t3.medium` worker nodes: **~$0.08/hour** |
| 89 | +- 1x NAT Gateway: **~$0.045/hour** |
| 90 | +- **Total: ~ $0.225/hour (~$5.40/day)** |
| 91 | + |
| 92 | +> Note: Data transfer and NAT data processing charges are additional. |
| 93 | +
|
| 94 | +## Cleanup |
| 95 | + |
| 96 | +```bash |
| 97 | +terraform destroy |
| 98 | +``` |
0 commit comments