-
Notifications
You must be signed in to change notification settings - Fork 46
/
executor.tf
159 lines (132 loc) · 3.42 KB
/
executor.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
locals {
auto_execute = var.auto_execute
leader_private_ip = aws_instance.leader.private_ip
executors = {
jmeter = {
nodes_ips = join(",", aws_instance.nodes.*.private_ip)
}
bzt = {
nodes_ips = "['${join("','", aws_instance.nodes.*.private_ip)}']"
}
locust = {
nodes_ips = join(",", aws_instance.nodes.*.private_ip)
leader_ip = local.leader_private_ip
}
k6 = {
waiting = "#"
nodes_ips = ""
}
}
executor = lookup(local.executors, var.executor, "")
waiting_command = "while [ ! -f /tmp/finished-setup ]; do echo 'waiting setup to be instaled'; sleep 5; done"
nodes_ips = local.executor.nodes_ips
entrypoint = replace(
replace(
var.loadtest_entrypoint,
"{NODES_IPS}",
local.nodes_ips
),
"{LEADER_IP}",
local.leader_private_ip
)
node_entrypoint = replace(
replace(
var.node_custom_entrypoint,
"{NODES_IPS}",
local.nodes_ips
),
"{LEADER_IP}",
local.leader_private_ip
)
}
resource "null_resource" "setup_leader" {
depends_on = [
aws_instance.leader,
aws_instance.nodes
]
connection {
host = coalesce(aws_instance.leader.public_ip, aws_instance.leader.private_ip)
type = "ssh"
user = var.ssh_user
private_key = tls_private_key.loadtest.private_key_pem
}
provisioner "remote-exec" {
inline = [
"echo 'SETUP'"
]
}
}
resource "null_resource" "setup_nodes" {
count = var.node_custom_entrypoint != "" ? var.nodes_size : 0
depends_on = [
aws_instance.leader,
aws_instance.nodes,
null_resource.executor,
]
connection {
host = coalesce(aws_instance.nodes[count.index].public_ip, aws_instance.nodes[count.index].private_ip)
type = "ssh"
user = var.ssh_user
private_key = tls_private_key.loadtest.private_key_pem
}
provisioner "remote-exec" {
inline = [
"echo SETUP NODES ${count.index}",
"echo '${local.node_entrypoint}'",
"cd ${var.loadtest_dir_destination}",
"${local.node_entrypoint}",
"sleep 1"
]
}
triggers = {
always_run = timestamp()
}
#LOCUST_EXPORTER_URI
#LOCUST_EXPORTER_TIMEOUT
#LOCUST_EXPORTER_WEB_LISTEN_ADDRESS
#LOCUST_EXPORTER_WEB_TELEMETRY_PATH
#locust_exporter_cmd="docker run --net=host containersol/locust_exporter"
}
resource "null_resource" "executor" {
count = local.auto_execute ? 1 : 0
depends_on = [
aws_instance.leader,
aws_instance.nodes,
null_resource.setup_leader,
null_resource.spliter_execute_command
]
connection {
host = coalesce(aws_instance.leader.public_ip, aws_instance.leader.private_ip)
type = "ssh"
user = var.ssh_user
private_key = tls_private_key.loadtest.private_key_pem
}
#WAITING FOR INSTANCE FINISHING SETUP
provisioner "remote-exec" {
inline = [
"echo 'START EXECUTION'",
local.waiting_command,
]
}
#CLEANING UP
provisioner "remote-exec" {
inline = [
"sudo chmod 777 /var/www/html -Rf",
"sudo rm -rf /var/www/html/*",
"sudo rm -rf /loadtest/logs",
]
}
#EXECUTING LOAD TEST
provisioner "remote-exec" {
inline = [
"echo DIR: ${var.loadtest_dir_destination}",
"cd ${var.loadtest_dir_destination}",
"echo '${local.entrypoint}'",
"${local.entrypoint}",
"sleep 1"
]
}
triggers = {
always_run = timestamp()
}
}