-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
92 lines (73 loc) · 2.18 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.70.0"
name = "${var.cluster_name}-vpc"
cidr = "172.16.0.0/16"
azs = data.aws_availability_zones.available.names
private_subnets = ["172.16.1.0/24", "172.16.2.0/24", "172.16.3.0/24"]
public_subnets = ["172.16.4.0/24", "172.16.5.0/24", "172.16.6.0/24"]
enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
public_subnet_tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/elb" = "1"
}
private_subnet_tags = {
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
}
tags = {
Terraform = "true"
Environment = "staging"
}
}
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "14.0.0"
cluster_name = var.cluster_name
cluster_version = var.cluster_version
subnets = module.vpc.private_subnets
vpc_id = module.vpc.vpc_id
// EKS Managed Node groups
node_groups = {
first = {
desired_capacity = 2
max_capacity = 10
min_capacity = 1
instance_type = var.instance_type
additional_tags = {
Role = "worker-ondemand"
}
}
second = {
desired_capacity = 2
max_capacity = 10
min_capacity = 1
instance_types = [var.instance_type]
capacity_type = "SPOT"
additional_tags = {
Role = "worker-spot"
}
}
}
write_kubeconfig = true
config_output_path = "./"
workers_additional_policies = [aws_iam_policy.worker_policy.arn]
tags = {
Name = var.cluster_name
Terraform = "true"
Environment = "staging"
}
depends_on = [module.vpc]
}
// Workaround for TargetGroupBinding CRDs installation
resource "null_resource" "target_group_crd" {
provisioner "local-exec" {
command = "kubectl apply -k 'github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master' --kubeconfig kubeconfig_${var.cluster_name}"
}
triggers = {
"eks_endpoint" = module.eks.cluster_endpoint
}
depends_on = [module.eks]
}