-
Notifications
You must be signed in to change notification settings - Fork 46
/
nodes.tf
110 lines (93 loc) · 2.61 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
resource "aws_instance" "nodes" {
count = var.nodes_size
ami = local.nodes_ami_id
instance_type = var.nodes_instance_type
associate_public_ip_address = var.nodes_associate_public_ip_address
monitoring = var.nodes_monitoring
subnet_id = var.subnet_id
vpc_security_group_ids = [aws_security_group.loadtest.id]
iam_instance_profile = aws_iam_instance_profile.loadtest.name
user_data_base64 = local.setup_nodes_base64
key_name = aws_key_pair.loadtest.key_name
connection {
host = coalesce(self.public_ip, self.private_ip)
type = "ssh"
user = var.ssh_user
private_key = tls_private_key.loadtest.private_key_pem
}
# CONFIG FILESYSTEM AND PERMITIONS
provisioner "remote-exec" {
inline = [
"echo '${tls_private_key.loadtest.private_key_pem}' > ~/.ssh/id_rsa",
"chmod 600 ~/.ssh/id_rsa",
"sudo mkdir -p ${var.loadtest_dir_destination} || true",
"sudo chown ${var.ssh_user}:${var.ssh_user} ${var.loadtest_dir_destination} || true"
]
}
# PUBLISH ALL FILES
provisioner "file" {
destination = var.loadtest_dir_destination
source = var.loadtest_dir_source
}
# WAITING FOR NODES TO BE READY
provisioner "remote-exec" {
inline = [
"echo 'START EXECUTION'",
"while [ ! -f /tmp/finished-setup ]; do echo 'waiting setup to be instaled'; sleep 5; done",
"sleep 10"
]
}
tags = merge(
var.tags,
var.nodes_tags
)
}
locals {
setup_nodes_executors = {
jmeter = {
node_user_data_base64 = base64encode(
templatefile(
"${path.module}/scripts/entrypoint.node.full.sh.tpl",
{
JVM_ARGS = var.nodes_jvm_args
}
)
)
}
bzt = {
node_user_data_base64 = base64encode(
templatefile(
"${path.module}/scripts/entrypoint.node.full.sh.tpl",
{
JVM_ARGS = var.nodes_jvm_args
}
)
)
}
locust = {
node_user_data_base64 = base64encode(
templatefile(
"${path.module}/scripts/locust.entrypoint.node.full.sh.tpl",
{}
)
)
}
k6 = {
node_user_data_base64 = base64encode(
templatefile(
"${path.module}/scripts/k6.entrypoint.node.full.sh.tpl",
{
JVM_ARGS = var.nodes_jvm_args
}
)
)
}
}
setup_nodes_executor = lookup(
local.setup_nodes_executors,
var.executor, {
node_user_data_base64 = var.nodes_custom_setup_base64
}
)
setup_nodes_base64 = local.setup_nodes_executor.node_user_data_base64
}