-
Notifications
You must be signed in to change notification settings - Fork 3
/
13.worker-nodes.tf
86 lines (64 loc) · 2.07 KB
/
13.worker-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
/* resource "aws_launch_template" "worker_node" {
name_prefix = "worker-node"
image_id = var.args.ami_id
instance_type = "t4g.small"
key_name = aws_key_pair.this.key_name
vpc_security_group_ids = [aws_security_group.node.id]
user_data = filebase64("${path.module}/outputs/kubeadm-join.as-worker.sh")
tag_specifications {
resource_type = "instance"
tags = {
KubernetesCluster = local.cluster_name
format("kubernetes.io/cluster/%v", local.cluster_name) = "1"
"node-type" = "worker"
}
}
}
resource "aws_autoscaling_group" "worker_nodes" {
name_prefix = "worker-nodes"
launch_template {
id = aws_launch_template.worker_node.id
}
vpc_zone_identifier = [for private_subnet in aws_subnet.private_subnets[*] : private_subnet.id]
min_size = 1
max_size = 3
} */
resource "aws_instance" "worker_nodes" {
count = local.master_node_count
subnet_id = aws_subnet.private_subnets[(count.index % length(local.availability_zones))].id
vpc_security_group_ids = [
aws_security_group.node.id
]
ami = var.args.ami_id
instance_type = "t4g.small"
root_block_device {
volume_size = 25
}
key_name = aws_key_pair.this.key_name
provisioner "remote-exec" {
connection {
host = self.private_ip
user = "ubuntu"
private_key = tls_private_key.this.private_key_pem
bastion_host = aws_instance.bastian_host.public_ip
bastion_user = "ubuntu"
bastion_private_key = tls_private_key.this.private_key_pem
}
when = create
on_failure = fail
scripts = [
"${path.module}/outputs/kubeadm-join.as-worker.sh"
]
}
tags = {
KubernetesCluster = local.cluster_name
format("kubernetes.io/cluster/%v", local.cluster_name) = "1"
"node-type" = "worker"
}
lifecycle {
ignore_changes = [
ami
]
}
depends_on = [null_resource.bootstrap_cluster]
}