-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathworker_nodes.tf
More file actions
68 lines (57 loc) · 1.9 KB
/
worker_nodes.tf
File metadata and controls
68 lines (57 loc) · 1.9 KB
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
# Create Node Group
resource "aws_eks_node_group" "eks_nodes_t2" {
cluster_name = aws_eks_cluster.eks_cluster.name
node_group_name = var.eks_node_group_name
subnet_ids = [aws_subnet.public_subnet[0].id]
node_role_arn = aws_iam_role.eks_node.arn
instance_types = var.eks_nodes_instance_types
disk_size = var.eks_nodes_disk_size
labels = var.eks_node_labels
scaling_config {
desired_size = var.eks_node_sc_desired_size
min_size = var.eks_node_sc_min_size
max_size = var.eks_node_sc_max_size
}
depends_on = [
aws_iam_role_policy_attachment.eks_node_policy,
]
tags = {
"Name" = "${aws_eks_cluster.eks_cluster.name}-eks-t2-medium-Node"
}
}
#####################
# Worker node lookup
#####################
data "aws_instances" "workers" {
instance_tags = {
"eks:nodegroup-name" = var.eks_node_group_name
}
depends_on = [aws_eks_node_group.eks_nodes_t2]
}
data "aws_instance" "workers" {
count = length(data.aws_instances.workers)
instance_id = element(data.aws_instances.workers.ids, count.index)
}
###########################################
# Adding a Security Group to a Worker Node
###########################################
resource "aws_network_interface_sg_attachment" "sg_attachment" {
count = length(data.aws_instance.workers)
security_group_id = aws_security_group.sg_allow_all.id
network_interface_id = element(data.aws_instance.workers.*.network_interface_id, count.index)
}
#####################################
# Elastic ip lookup for worker nodes
#####################################
data "aws_eip" "worker_node_eip" {
tags = {
Name = var.worker_node_eip_name
}
}
##################################
# EIP connections to worker nodes
##################################
resource "aws_eip_association" "worker_node_eip_assoc" {
instance_id = data.aws_instance.workers[0].id
allocation_id = data.aws_eip.worker_node_eip.id
}