-
Notifications
You must be signed in to change notification settings - Fork 28
/
asg.tf
146 lines (125 loc) · 3.81 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
resource "aws_autoscaling_group" "k8s_servers_asg" {
name = "${var.common_prefix}-servers-asg-${var.environment}"
wait_for_capacity_timeout = "5m"
vpc_zone_identifier = var.vpc_private_subnets
lifecycle {
create_before_destroy = true
ignore_changes = [load_balancers, target_group_arns]
}
mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = 0
on_demand_percentage_above_base_capacity = 20
spot_allocation_strategy = "capacity-optimized"
}
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.k8s_server.id
version = "$Latest"
}
dynamic "override" {
for_each = var.instance_types
content {
instance_type = override.value
weighted_capacity = "1"
}
}
}
}
desired_capacity = var.k8s_server_desired_capacity
min_size = var.k8s_server_min_capacity
max_size = var.k8s_server_max_capacity
health_check_grace_period = 300
health_check_type = "EC2"
force_delete = true
dynamic "tag" {
for_each = local.global_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
tag {
key = "Name"
value = "${var.common_prefix}-server-${var.environment}"
propagate_at_launch = true
}
tag {
key = "k8s-instance-type"
value = "k8s-server"
propagate_at_launch = true
}
tag {
key = "k8s.io/cluster-autoscaler/enabled"
value = ""
propagate_at_launch = true
}
tag {
key = "k8s.io/cluster-autoscaler/${var.cluster_name}"
value = ""
propagate_at_launch = true
}
}
resource "aws_autoscaling_group" "k8s_workers_asg" {
name = "${var.common_prefix}-workers-asg-${var.environment}"
vpc_zone_identifier = var.vpc_private_subnets
lifecycle {
create_before_destroy = true
ignore_changes = [load_balancers, target_group_arns]
}
mixed_instances_policy {
instances_distribution {
on_demand_base_capacity = 0
on_demand_percentage_above_base_capacity = 20
spot_allocation_strategy = "capacity-optimized"
}
launch_template {
launch_template_specification {
launch_template_id = aws_launch_template.k8s_worker.id
version = "$Latest"
}
dynamic "override" {
for_each = var.instance_types
content {
instance_type = override.value
weighted_capacity = "1"
}
}
}
}
desired_capacity = var.k8s_worker_desired_capacity
min_size = var.k8s_worker_min_capacity
max_size = var.k8s_worker_max_capacity
health_check_grace_period = 300
health_check_type = "EC2"
force_delete = true
dynamic "tag" {
for_each = local.global_tags
content {
key = tag.key
value = tag.value
propagate_at_launch = true
}
}
tag {
key = "Name"
value = "${var.common_prefix}-worker-${var.environment}"
propagate_at_launch = true
}
tag {
key = "k8s-instance-type"
value = "k8s-worker"
propagate_at_launch = true
}
tag {
key = "k8s.io/cluster-autoscaler/enabled"
value = ""
propagate_at_launch = true
}
tag {
key = "k8s.io/cluster-autoscaler/${var.cluster_name}"
value = ""
propagate_at_launch = true
}
}