|
| 1 | +############################################################################### |
| 2 | +# 1. Tiny VPC (skip if you already have one) |
| 3 | +############################################################################### |
| 4 | +data "aws_availability_zones" "available" { state = "available" } |
| 5 | + |
| 6 | +locals { |
| 7 | + azs = slice(data.aws_availability_zones.available.names, 0, 2) |
| 8 | +} |
| 9 | + |
| 10 | + |
| 11 | +module "vpc" { |
| 12 | + source = "terraform-aws-modules/vpc/aws" |
| 13 | + version = "~> 5.0" |
| 14 | + |
| 15 | + name = "${var.project_name}-${var.environment}-vpc" |
| 16 | + cidr = "10.10.0.0/24" |
| 17 | + azs = local.azs |
| 18 | + |
| 19 | + public_subnets = ["10.10.0.0/26", "10.10.0.64/26"] # /26 = 64 IPs |
| 20 | + private_subnets = ["10.10.0.128/26","10.10.0.192/26"] |
| 21 | + |
| 22 | + enable_nat_gateway = true # keep it ultra-minimal |
| 23 | + single_nat_gateway = true |
| 24 | + |
| 25 | + tags = var.global_tags |
| 26 | +} |
| 27 | + |
| 28 | +############################################################################### |
| 29 | +# 2. EKS cluster (minimal) |
| 30 | +############################################################################### |
| 31 | +module "eks" { |
| 32 | + source = "terraform-aws-modules/eks/aws" |
| 33 | + version = "~> 20.0" |
| 34 | + |
| 35 | + cluster_name = "${var.project_name}-${var.environment}-eks" |
| 36 | + cluster_version = "1.28" |
| 37 | + subnet_ids = module.vpc.private_subnets |
| 38 | + vpc_id = module.vpc.vpc_id |
| 39 | + |
| 40 | + #access |
| 41 | + cluster_endpoint_public_access = true |
| 42 | + cluster_endpoint_public_access_cidrs = [ |
| 43 | + "136.57.60.172/32", |
| 44 | + "0.0.0.0/0" |
| 45 | + ] |
| 46 | + |
| 47 | + |
| 48 | + # One small managed node group |
| 49 | + eks_managed_node_groups = {} |
| 50 | + fargate_profiles = { |
| 51 | + all = { |
| 52 | + selectors = [{ namespace = "default" }] |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + # map the GitHub OIDC deploy role so CI can kubectl |
| 57 | + access_entries = { |
| 58 | + github-ci = { |
| 59 | + principal_arn = aws_iam_role.github_deploy.arn |
| 60 | + kubernetes_groups = ["cluster-admin"] |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + cluster_enabled_log_types = [ |
| 65 | + "api", "audit", "authenticator", "controllerManager", "scheduler" |
| 66 | + ] |
| 67 | + |
| 68 | + cloudwatch_log_group_retention_in_days = 30 |
| 69 | + |
| 70 | + tags = var.global_tags |
| 71 | +} |
| 72 | + |
| 73 | +# aws-for-fluent-bit add-on (EKS add-ons support add-ons/v1 API) |
| 74 | +# resource "aws_eks_addon" "fluentbit" { |
| 75 | +# cluster_name = module.eks.cluster_name |
| 76 | +# addon_name = "aws-for-fluent-bit" |
| 77 | +# addon_version = "v2.31.0-eksbuild.1" # latest as of 2025-07 |
| 78 | +# resolve_conflicts_on_create = "OVERWRITE" |
| 79 | + |
| 80 | +# tags = var.global_tags |
| 81 | +# } |
| 82 | + |
| 83 | +# resource "aws_cloudwatch_log_group" "app_logs" { |
| 84 | +# name = "/aws/containerinsights/${module.eks.cluster_name}/application" |
| 85 | +# retention_in_days = 30 |
| 86 | +# } |
| 87 | + |
| 88 | +output "cluster_name" { value = module.eks.cluster_name } |
| 89 | +output "cluster_endpoint" { value = module.eks.cluster_endpoint } |
| 90 | +output "cluster_ca" { value = module.eks.cluster_certificate_authority_data } |
| 91 | + |
0 commit comments