################################################################################ # EKS Cluster ################################################################################ module "eks" { source = "terraform-aws-modules/eks/aws" version = "~> 19.15" cluster_name = local.name cluster_version = "1.27" cluster_addons = { coredns = {} kube-proxy = {} vpc-cni = {} } cluster_security_group_additional_rules = { # Allow tcp/443 from the NLB IP addresses for ip_addr in data.dns_a_record_set.nlb.addrs : "nlb_ingress_${replace(ip_addr, ".", "")}" => { description = "Allow ingress from NLB" type = "ingress" from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = ["${ip_addr}/32"] } } vpc_id = module.vpc.vpc_id subnet_ids = module.vpc.private_subnets eks_managed_node_groups = { default = { instance_types = ["c5.large"] min_size = 1 max_size = 3 desired_size = 1 } } tags = local.tags } ################################################################################ # VPC ################################################################################ module "vpc" { source = "terraform-aws-modules/vpc/aws" version = "~> 5.0" name = local.name cidr = local.vpc_cidr azs = local.azs private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)] # Disable NAT gateway for fully private networking enable_nat_gateway = false private_subnet_tags = { "kubernetes.io/role/internal-elb" = 1 } tags = local.tags } # Explicitly create a Internet Gateway here in the Private EKS VPC as without an # internet gateway, a NLB cannot be created. Config option of create_igw = true # (default) did not work during the VPC creation as it requires public subnets # and the related routes that connect them to IGW resource "aws_internet_gateway" "igw" { vpc_id = module.vpc.vpc_id tags = local.tags } ################################################################################ # VPC Endpoints ################################################################################ module "vpc_endpoints" { source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints" version = "~> 5.1" vpc_id = module.vpc.vpc_id # Security group create_security_group = true security_group_name_prefix = "${local.name}-vpc-endpoints-" security_group_description = "VPC endpoint security group" security_group_rules = { ingress_https = { description = "HTTPS from VPC" cidr_blocks = [module.vpc.vpc_cidr_block] } } endpoints = merge({ s3 = { service = "s3" service_type = "Gateway" route_table_ids = module.vpc.private_route_table_ids tags = { Name = "${local.name}-s3" } } }, { for service in toset(["autoscaling", "ecr.api", "ecr.dkr", "ec2", "ec2messages", "elasticloadbalancing", "sts", "kms", "logs", "ssm", "ssmmessages"]) : replace(service, ".", "_") => { service = service subnet_ids = module.vpc.private_subnets private_dns_enabled = true tags = { Name = "${local.name}-${service}" } } }) tags = local.tags }