-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathazure_remote_public_agent.tf
426 lines (375 loc) · 18.5 KB
/
azure_remote_public_agent.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# Public Agent
resource "azurerm_managed_disk" "public_agent_managed_disk-remote" {
count = "${var.num_of_remote_azure_public_agents}"
name = "${data.template_file.cluster-name.rendered}-remote-public-agent-${count.index + 1}"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "${var.instance_disk_size}"
}
# mbernadin: Public Agent Load Balancer Settings for Public and Private
# Public IP addresses for the Public Front End load Balancer
resource "azurerm_public_ip" "public_agent_load_balancer_public_ip-remote" {
name = "${data.template_file.cluster-name.rendered}-remote-public-lb-ip"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
public_ip_address_allocation = "dynamic"
domain_name_label = "public-agent-${data.template_file.cluster-name.rendered}"
tags {
Name = "${coalesce(var.owner, data.external.whoami.result["owner"])}"
expiration = "${var.expiration}"
}
}
# Public IP addresses for the Public Front End load Balancer
resource "azurerm_public_ip" "public_agent_public_ip-remote" {
count = "${var.num_of_remote_azure_public_agents}"
name = "${data.template_file.cluster-name.rendered}-remote-public-agent-pub-ip-${count.index + 1}"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
public_ip_address_allocation = "dynamic"
domain_name_label = "${data.template_file.cluster-name.rendered}-remote-public-agent-${count.index + 1}"
tags {
Name = "${coalesce(var.owner, data.external.whoami.result["owner"])}"
expiration = "${var.expiration}"
}
}
# Front End Load Balancer
resource "azurerm_lb" "public_agent_public_load_balancer-remote" {
name = "${data.template_file.cluster-name.rendered}-remote-pub-agent-elb"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
frontend_ip_configuration {
name = "${data.template_file.cluster-name.rendered}-remote-public-agent-ip-config"
public_ip_address_id = "${azurerm_public_ip.public_agent_load_balancer_public_ip-remote.id}"
}
tags {
Name = "${coalesce(var.owner, data.external.whoami.result["owner"])}"
expiration = "${var.expiration}"
}
}
# Back End Address Pool for Public and Private Loadbalancers
resource "azurerm_lb_backend_address_pool" "external_public_agent_backend_pool-remote" {
name = "${data.template_file.cluster-name.rendered}-remote-public_backend_address_pool"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
loadbalancer_id = "${azurerm_lb.public_agent_public_load_balancer-remote.id}"
}
# Load Balancer Rule
resource "azurerm_lb_rule" "agent_public_load_balancer_http_rule-remote" {
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
loadbalancer_id = "${azurerm_lb.public_agent_public_load_balancer-remote.id}"
name = "HTTPRule"
protocol = "Tcp"
frontend_port = 80
backend_port = 80
frontend_ip_configuration_name = "${data.template_file.cluster-name.rendered}-remote-public-agent-ip-config"
backend_address_pool_id = "${azurerm_lb_backend_address_pool.external_public_agent_backend_pool-remote.id}"
probe_id = "${azurerm_lb_probe.agent_load_balancer_http_probe-remote.id}"
depends_on = ["azurerm_lb_probe.agent_load_balancer_http_probe-remote"]
}
# Load Balancer Rule
resource "azurerm_lb_rule" "agent_public_load_balancer_https_rule-remote" {
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
loadbalancer_id = "${azurerm_lb.public_agent_public_load_balancer-remote.id}"
name = "HTTPSRule"
protocol = "Tcp"
frontend_port = 443
backend_port = 443
frontend_ip_configuration_name = "${data.template_file.cluster-name.rendered}-remote-public-agent-ip-config"
backend_address_pool_id = "${azurerm_lb_backend_address_pool.external_public_agent_backend_pool-remote.id}"
probe_id = "${azurerm_lb_probe.agent_load_balancer_https_probe-remote.id}"
depends_on = ["azurerm_lb_probe.agent_load_balancer_https_probe-remote"]
}
#LB Probe - Checks to see which VMs are healthy and available
resource "azurerm_lb_probe" "agent_load_balancer_http_probe-remote" {
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
loadbalancer_id = "${azurerm_lb.public_agent_public_load_balancer-remote.id}"
name = "HTTP"
port = 80
}
#LB Probe - Checks to see which VMs are healthy and available
resource "azurerm_lb_probe" "agent_load_balancer_https_probe-remote" {
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
loadbalancer_id = "${azurerm_lb.public_agent_public_load_balancer-remote.id}"
name = "HTTPS"
port = 443
}
# Public Agent Security Groups for NICs
resource "azurerm_network_security_group" "public_agent_security_group-remote" {
name = "${data.template_file.cluster-name.rendered}-remote-public-agent-security-group"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
tags {
Name = "${coalesce(var.owner, data.external.whoami.result["owner"])}"
expiration = "${var.expiration}"
}
}
resource "azurerm_network_security_rule" "public-agent-sshRule-remote" {
name = "sshRule"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
resource "azurerm_network_security_rule" "public-agent-httpRule-remote" {
name = "HTTP"
priority = 110
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
resource "azurerm_network_security_rule" "public-agent-httpsRule-remote" {
name = "HTTPS"
priority = 120
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "443"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
resource "azurerm_network_security_rule" "public-agent-RangeOne-remote" {
name = "RangeOne"
priority = 130
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "0-21"
destination_port_range = "0-21"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
resource "azurerm_network_security_rule" "public-agent-RangeTwo-remote" {
name = "RangeTwo"
priority = 140
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "23-5050"
destination_port_range = "23-5050"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
resource "azurerm_network_security_rule" "public-agent-RangeThree-remote" {
name = "RangeThree"
priority = 150
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "5052-32000"
destination_port_range = "5052-32000"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
resource "azurerm_network_security_rule" "public-agent-internalEverything-remote" {
name = "allOtherInternalTraffric"
priority = 160
direction = "Inbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "10.0.0.0/8"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
resource "azurerm_network_security_rule" "public-agent-everythingElseOutBound-remote" {
name = "allOtherTrafficOutboundRule"
priority = 170
direction = "Outbound"
access = "Allow"
protocol = "*"
source_port_range = "*"
destination_port_range = "*"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_name = "${azurerm_network_security_group.public_agent_security_group-remote.name}"
}
# End of Public Agent NIC Security Group
# Public Agent NICs with Security Group
resource "azurerm_network_interface" "public_agent_nic-remote" {
name = "${data.template_file.cluster-name.rendered}-remote-public-agent-${count.index}-nic"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_security_group_id = "${azurerm_network_security_group.public_agent_security_group-remote.id}"
enable_ip_forwarding = "true"
count = "${var.num_of_remote_azure_public_agents}"
ip_configuration {
name = "${data.template_file.cluster-name.rendered}-pub-remote-${count.index}-ipConfig"
subnet_id = "${azurerm_subnet.public_remote.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${element(azurerm_public_ip.public_agent_public_ip-remote.*.id, count.index)}"
load_balancer_backend_address_pools_ids = ["${azurerm_lb_backend_address_pool.external_public_agent_backend_pool-remote.id}"]
}
tags {
Name = "${coalesce(var.owner, data.external.whoami.result["owner"])}"
expiration = "${var.expiration}"
}
}
# Create an availability set
resource "azurerm_availability_set" "public_agent_av_set-remote" {
name = "${data.template_file.cluster-name.rendered}-remote-public-agent-avset"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
platform_fault_domain_count = 2
platform_update_domain_count = 1
managed = true
}
# Public Agent VM Coniguration
resource "azurerm_virtual_machine" "public-agent-remote" {
name = "${data.template_file.cluster-name.rendered}-remote-public-agent-${count.index + 1}"
location = "${var.azure_remote_region}"
resource_group_name = "${azurerm_resource_group.dcos_remote.name}"
network_interface_ids = ["${azurerm_network_interface.public_agent_nic-remote.*.id[count.index]}"]
availability_set_id = "${azurerm_availability_set.public_agent_av_set-remote.id}"
vm_size = "${var.azure_public_agent_instance_type}"
count = "${var.num_of_remote_azure_public_agents}"
delete_os_disk_on_termination = true
delete_data_disks_on_termination = true
storage_image_reference {
publisher = "${module.azure-tested-oses.azure_publisher}"
offer = "${module.azure-tested-oses.azure_offer}"
sku = "${module.azure-tested-oses.azure_sku}"
version = "${module.azure-tested-oses.azure_version}"
}
storage_os_disk {
name = "os-disk-public-agent-${count.index + 1}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_data_disk {
name = "${azurerm_managed_disk.public_agent_managed_disk-remote.*.name[count.index]}"
managed_disk_id = "${azurerm_managed_disk.public_agent_managed_disk-remote.*.id[count.index]}"
create_option = "Attach"
lun = 0
disk_size_gb = "${azurerm_managed_disk.public_agent_managed_disk-remote.*.disk_size_gb[count.index]}"
}
os_profile {
computer_name = "public-agent-${count.index + 1}"
admin_username = "${coalesce(var.azure_admin_username, module.azure-tested-oses.user)}"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/${coalesce(var.azure_admin_username, module.azure-tested-oses.user)}/.ssh/authorized_keys"
key_data = "${var.ssh_pub_key}"
}
}
# OS init script
provisioner "file" {
content = "${module.azure-tested-oses.os-setup}"
destination = "/tmp/os-setup.sh"
connection {
type = "ssh"
user = "${coalesce(var.azure_admin_username, module.azure-tested-oses.user)}"
host = "${element(azurerm_public_ip.public_agent_public_ip-remote.*.fqdn, count.index)}"
private_key = "${local.private_key}"
agent = "${local.agent}"
}
}
# We run a remote provisioner on the instance after creating it.
# In this case, we just install nginx and start it. By default,
# this should be on port 80
provisioner "remote-exec" {
inline = [
"sudo chmod +x /tmp/os-setup.sh",
"sudo bash /tmp/os-setup.sh",
]
connection {
type = "ssh"
user = "${coalesce(var.azure_admin_username, module.azure-tested-oses.user)}"
host = "${element(azurerm_public_ip.public_agent_public_ip-remote.*.fqdn, count.index)}"
private_key = "${local.private_key}"
agent = "${local.agent}"
}
}
tags {
Name = "${coalesce(var.owner, data.external.whoami.result["owner"])}"
expiration = "${var.expiration}"
}
}
# Create DCOS Mesos Public Agent Scripts to execute
module "azure-dcos-mesos-agent-public-remote" {
source = "github.com/dcos/tf_dcos_core"
bootstrap_private_ip = "${azurerm_network_interface.bootstrap_nic.private_ip_address}"
dcos_bootstrap_port = "${var.custom_dcos_bootstrap_port}"
# Only allow upgrade and install as installation mode
dcos_install_mode = "${var.state == "upgrade" ? "upgrade" : "install"}"
dcos_version = "${var.dcos_version}"
dcos_type = "${var.dcos_type}"
role = "dcos-mesos-agent-public"
}
resource "null_resource" "public-agent-remote" {
# If state is set to none do not install DC/OS
count = "${var.state == "none" ? 0 : var.num_of_remote_azure_public_agents}"
# Changes to any instance of the cluster requires re-provisioning
triggers {
cluster_instance_ids = "${null_resource.azure-bootstrap.id}"
current_virtual_machine_id = "${azurerm_virtual_machine.public-agent-remote.*.id[count.index]}"
}
# Bootstrap script can run on any instance of the cluster
# So we just choose the first in this case
connection {
host = "${element(azurerm_public_ip.public_agent_public_ip-remote.*.fqdn, count.index)}"
user = "${coalesce(var.azure_admin_username, module.azure-tested-oses.user)}"
private_key = "${local.private_key}"
agent = "${local.agent}"
}
count = "${var.num_of_remote_azure_public_agents}"
# Generate and upload Public Agent script to node
provisioner "file" {
content = "${module.azure-dcos-mesos-agent-public.script}"
destination = "run.sh"
}
# Wait for bootstrapnode to be ready
provisioner "remote-exec" {
inline = [
"until $(curl --output /dev/null --silent --head --fail http://${azurerm_network_interface.bootstrap_nic.private_ip_address}:${var.custom_dcos_bootstrap_port}/dcos_install.sh); do printf 'waiting for bootstrap node to serve...'; sleep 20; done"
]
}
# Install Public Agent Script
provisioner "remote-exec" {
inline = [
"sudo chmod +x run.sh",
"sudo ./run.sh"
]
}
# Mesos poststart check workaround. Engineering JIRA filed to Mesosphere team to fix.
provisioner "remote-exec" {
inline = [
"sudo sed -i.bak '131 s/1s/10s/' /opt/mesosphere/packages/dcos-config--setup*/etc/dcos-diagnostics-runner-config.json &> /dev/null || true",
"sudo sed -i.bak '140 s/1s/10s/' /opt/mesosphere/packages/dcos-config--setup*/etc/dcos-check-config.json &> /dev/null || true",
"sudo sed -i.bak '162 s/1s/10s/' /opt/mesosphere/packages/dcos-config--setup*/etc/dcos-diagnostics-runner-config.json &> /dev/null || true"
]
}
}
output "Azure Public Agent ELB Address-remote" {
value = "${azurerm_public_ip.public_agent_load_balancer_public_ip-remote.fqdn}"
}
output "Public Agent Public IPs-remote" {
value = ["${azurerm_public_ip.public_agent_public_ip-remote.*.fqdn}"]
}