-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.tf
113 lines (91 loc) · 2.73 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
resource "aws_key_pair" "deployer" {
key_name = "${var.name}-${timestamp()}-key"
public_key = tls_private_key.temp.public_key_openssh
lifecycle {
ignore_changes = [
key_name,
]
}
}
resource "tls_private_key" "temp" {
algorithm = "RSA"
}
resource "aws_instance" "master" {
ami = var.node_ami
instance_type = "t2.micro"
key_name = aws_key_pair.deployer.key_name
network_interface {
device_index = var.use_private_ip ? 1 : 0
network_interface_id = aws_network_interface.master_public_network_interface.id
}
dynamic "network_interface" {
for_each = var.use_private_ip ? [1] : []
content {
device_index = 0
network_interface_id = aws_network_interface.master_private_network_interface[0].id
}
}
tags = {
Name = "${var.name}-master"
}
depends_on = [
aws_security_group.nodes
]
provisioner "file" {
source = "${path.module}/supervisord.conf"
destination = "supervisord.conf"
}
provisioner "file" {
source = "${var.scripts_folder}/"
destination = "/home/ec2-user/"
}
provisioner "remote-exec" {
inline = var.use_private_ip ? concat(local.configure_private_network, local.install_locust_master) : local.install_locust_master
}
connection {
host = var.use_private_ip ? self.private_ip : self.public_ip
type = "ssh"
user = "ec2-user"
private_key = tls_private_key.temp.private_key_pem
}
}
resource "aws_instance" "worker" {
count = var.number_of_workers
ami = var.node_ami
instance_type = var.worker_instance_type
key_name = aws_key_pair.deployer.key_name
network_interface {
device_index = var.use_private_ip ? 1 : 0
network_interface_id = aws_network_interface.worker_public_network_interface[count.index].id
}
dynamic "network_interface" {
for_each = var.use_private_ip ? [1] : []
content {
device_index = 0
network_interface_id = aws_network_interface.worker_private_network_interface[count.index].id
}
}
tags = {
Name = "${var.name}-worker"
}
depends_on = [
aws_security_group.nodes
]
provisioner "file" {
source = "${path.module}/supervisord.conf"
destination = "supervisord.conf"
}
provisioner "file" {
source = "${var.scripts_folder}/"
destination = "/home/ec2-user/"
}
provisioner "remote-exec" {
inline = var.use_private_ip ? concat(local.configure_private_network, local.install_locust_worker) : local.install_locust_worker
}
connection {
host = var.use_private_ip ? self.private_ip : self.public_ip
type = "ssh"
user = "ec2-user"
private_key = tls_private_key.temp.private_key_pem
}
}