1
+
2
+
3
+ locals {
4
+ # VPC - existing or new?
5
+ vpc_id = var. vpc_id == " " ? module. vpc . vpc_id : var. vpc_id
6
+ public_subnet_ids = coalescelist (module. vpc . public_subnets , var. public_subnet_ids , [" " ])
7
+ private_subnet_ids = coalescelist (module. vpc . private_subnets , var. private_subnet_ids , [" " ])
8
+ private_subnets_cidr_blocks = coalescelist (module. vpc . private_subnets_cidr_blocks , var. private_subnets_cidr_blocks , [" " ])
9
+ }
10
+
11
+ data "aws_region" "current" {}
12
+
13
+ # ##################
14
+ # VPC
15
+ # ##################
16
+
17
+ module "vpc" {
18
+ source = " terraform-aws-modules/vpc/aws"
19
+ version = " ~> 3.0"
20
+
21
+ create_vpc = var. vpc_id == " "
22
+
23
+ name = var. name
24
+
25
+ cidr = var. cidr
26
+ azs = var. azs
27
+ public_subnets = var. public_subnets
28
+ private_subnets = var. private_subnets
29
+
30
+ enable_nat_gateway = true
31
+ single_nat_gateway = true
32
+
33
+ }
34
+
35
+ # ##################
36
+ # Security groups
37
+ # ##################
38
+
39
+ module "eks_sg" {
40
+ source = " terraform-aws-modules/security-group/aws"
41
+ version = " ~> 4.0"
42
+
43
+ name = " eks-sg"
44
+ vpc_id = local. vpc_id
45
+ description = " Allow outbound connections to the world"
46
+
47
+ ingress_cidr_blocks = [" 0.0.0.0/0" ]
48
+
49
+ egress_rules = [" all-all" ]
50
+
51
+ }
52
+
53
+ # ##################
54
+ # EKS
55
+ # ##################
56
+
57
+ module "eks" {
58
+ source = " terraform-aws-modules/eks/aws"
59
+
60
+ cluster_name = " cloudquery-eks"
61
+ cluster_version = " 1.21"
62
+ cluster_endpoint_private_access = true
63
+ cluster_endpoint_public_access = true
64
+
65
+ cluster_addons = {
66
+ coredns = {
67
+ resolve_conflicts = " OVERWRITE"
68
+ }
69
+ kube-proxy = {}
70
+ vpc-cni = {
71
+ resolve_conflicts = " OVERWRITE"
72
+ }
73
+ }
74
+
75
+
76
+ vpc_id = local. vpc_id
77
+ subnet_ids = local. private_subnet_ids
78
+
79
+ // # EKS Managed Node Group(s)
80
+ eks_managed_node_group_defaults = {
81
+ ami_type = " AL2_x86_64"
82
+ disk_size = 100
83
+ instance_types = [" m5.large" ]
84
+ vpc_security_group_ids = [module.eks_sg.security_group_id]
85
+ }
86
+
87
+ eks_managed_node_groups = {
88
+ # Default node group - as provided by AWS EKS
89
+ default_node_group = {
90
+ # By default, the module creates a launch template to ensure tags are propagated to instances, etc.,
91
+ # so we need to disable it to use the default template provided by the AWS EKS managed node group service
92
+ create_launch_template = false
93
+ launch_template_name = " "
94
+ max_size = 2
95
+ desired_size = 1
96
+ }
97
+ }
98
+
99
+ }
0 commit comments