-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.tf
172 lines (137 loc) · 3.87 KB
/
nodes.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
data "aws_subnets" "eks_private_subnets" {
filter {
name = "vpc-id"
values = [aws_vpc.eks_vpc.id]
}
tags = {
Name = "*private*"
}
depends_on = [
aws_subnet.eks_private_subnets
]
}
data "aws_instances" "stateful" {
instance_tags = {
"eks:nodegroup-name" = "${var.eks_name}-stateful"
}
filter {
name = "vpc-id"
values = [aws_vpc.eks_vpc.id]
}
instance_state_names = ["running", "pending"]
depends_on = [
aws_eks_node_group.stateful
]
}
data "aws_instances" "spot" {
instance_tags = {
"eks:nodegroup-name" = "${var.eks_name}-spot"
}
filter {
name = "vpc-id"
values = [aws_vpc.eks_vpc.id]
}
instance_state_names = ["running", "pending"]
depends_on = [
aws_eks_node_group.spot
]
}
data "aws_ssm_parameter" "eks_ami_release_version" {
name = "/aws/service/eks/optimized-ami/${aws_eks_cluster.eks.version}/amazon-linux-2/recommended/release_version"
}
resource "aws_eks_node_group" "stateful" {
cluster_name = aws_eks_cluster.eks.name
node_group_name = "${var.eks_name}-stateful"
version = aws_eks_cluster.eks.version
release_version = nonsensitive(data.aws_ssm_parameter.eks_ami_release_version.value)
node_role_arn = aws_iam_role.nodes.arn
subnet_ids = data.aws_subnets.eks_private_subnets.ids
ami_type = "AL2_x86_64"
capacity_type = "ON_DEMAND"
disk_size = 30
instance_types = ["t2.medium"]
scaling_config {
desired_size = var.desired_size
max_size = var.max_size
min_size = var.min_size
}
update_config {
max_unavailable = 1
}
lifecycle {
ignore_changes = [scaling_config[0].desired_size]
}
depends_on = [
aws_iam_role_policy_attachment.nodes_AmazonEKSWorkerNodePolicy,
aws_iam_role_policy_attachment.nodes_AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.nodes_AmazonEC2ContainerRegistryReadOnly
]
}
resource "aws_eks_node_group" "spot" {
cluster_name = aws_eks_cluster.eks.name
node_group_name = "${var.eks_name}-spot"
version = aws_eks_cluster.eks.version
release_version = nonsensitive(data.aws_ssm_parameter.eks_ami_release_version.value)
node_role_arn = aws_iam_role.nodes.arn
subnet_ids = data.aws_subnets.eks_private_subnets.ids
ami_type = "AL2_x86_64"
capacity_type = "SPOT"
disk_size = 30
instance_types = ["t2.medium"]
scaling_config {
desired_size = var.desired_size
max_size = var.max_size
min_size = var.min_size
}
update_config {
max_unavailable = 1
}
lifecycle {
ignore_changes = [scaling_config[0].desired_size]
}
depends_on = [
aws_iam_role_policy_attachment.nodes_AmazonEKSWorkerNodePolicy,
aws_iam_role_policy_attachment.nodes_AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.nodes_AmazonEC2ContainerRegistryReadOnly
]
}
resource "aws_autoscaling_group_tag" "stateful" {
autoscaling_group_name = aws_eks_node_group.stateful.resources[0].autoscaling_groups[0].name
tag {
key = "Name"
value = "${var.eks_name}-stateful"
propagate_at_launch = true
}
depends_on = [
aws_eks_node_group.stateful
]
}
resource "aws_autoscaling_group_tag" "spot" {
autoscaling_group_name = aws_eks_node_group.spot.resources[0].autoscaling_groups[0].name
tag {
key = "Name"
value = "${var.eks_name}-spot"
propagate_at_launch = true
}
depends_on = [
aws_eks_node_group.spot
]
}
resource "aws_ec2_tag" "stateful" {
count = var.desired_size
resource_id = data.aws_instances.stateful.ids[count.index]
key = "Name"
value = "${var.eks_name}-stateful"
depends_on = [
aws_eks_node_group.stateful
]
}
resource "aws_ec2_tag" "spot" {
count = var.desired_size
resource_id = data.aws_instances.spot.ids[count.index]
key = "Name"
value = "${var.eks_name}-spot"
depends_on = [
aws_eks_node_group.spot
]
}