forked from nimbux911/terraform-aws-eks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asg.tf
96 lines (84 loc) · 3.16 KB
/
asg.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
93
94
95
96
locals {
eks_worker_userdata_max_pods_enabled = <<USERDATA
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh --apiserver-endpoint '${aws_eks_cluster.main.endpoint}' --b64-cluster-ca '${aws_eks_cluster.main.certificate_authority.0.data}' '${aws_eks_cluster.main.name}' --use-max-pods false --kubelet-extra-args '--max-pods=${var.max_pods_per_node}'
USERDATA
eks_worker_userdata = <<USERDATA
#!/bin/bash
set -o xtrace
/etc/eks/bootstrap.sh --apiserver-endpoint '${aws_eks_cluster.main.endpoint}' --b64-cluster-ca '${aws_eks_cluster.main.certificate_authority.0.data}' '${aws_eks_cluster.main.name}'
USERDATA
}
resource "aws_key_pair" "eks" {
key_name = aws_eks_cluster.main.name
public_key = base64decode(aws_ssm_parameter.eks_public_key.value)
tags = var.eks_tags
}
resource "aws_launch_configuration" "eks" {
iam_instance_profile = aws_iam_instance_profile.eks_worker.name
image_id = var.eks_worker_ami_id
instance_type = var.instance_type
name_prefix = aws_eks_cluster.main.name
security_groups = [aws_security_group.eks_worker.id]
user_data_base64 = var.eks_worker_max_pods_enabled ? base64encode(local.eks_worker_userdata_max_pods_enabled) : base64encode(local.eks_worker_userdata)
key_name = aws_key_pair.eks.key_name
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "eks" {
count = var.ignore_desired_capacity || var.helm_cluster_autoscaler_enabled ? 0 : 1
desired_capacity = var.desired_capacity
launch_configuration = aws_launch_configuration.eks.id
max_size = var.max_size
min_size = var.min_size
name = var.cluster_name
vpc_zone_identifier = var.subnets_ids
target_group_arns = var.target_group_arns
health_check_type = var.health_check_type
tags = concat(
[
{
"key" = "Name"
"value" = var.cluster_name
"propagate_at_launch" = true
},
{
"key" = "kubernetes.io/cluster/${aws_eks_cluster.main.name}"
"value" = "owned"
"propagate_at_launch" = true
},
],
var.asg_tags,
)
}
resource "aws_autoscaling_group" "eks_ignore_desired_capacity" {
count = var.ignore_desired_capacity || var.helm_cluster_autoscaler_enabled ? 1 : 0
desired_capacity = var.desired_capacity
launch_configuration = aws_launch_configuration.eks.id
max_size = var.max_size
min_size = var.min_size
name = var.cluster_name
vpc_zone_identifier = var.subnets_ids
target_group_arns = var.target_group_arns
health_check_type = var.health_check_type
tags = concat(
[
{
"key" = "Name"
"value" = var.cluster_name
"propagate_at_launch" = true
},
{
"key" = "kubernetes.io/cluster/${aws_eks_cluster.main.name}"
"value" = "owned"
"propagate_at_launch" = true
},
],
var.asg_tags,
)
lifecycle {
ignore_changes = [desired_capacity]
}
}