-
Notifications
You must be signed in to change notification settings - Fork 4
/
server_load_labancer.tf
78 lines (67 loc) · 2.06 KB
/
server_load_labancer.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
data "cloudinit_config" "load_balancer" {
gzip = false
base64_encode = false
part {
filename = "cloud-config.yaml"
content_type = "text/cloud-config"
content = yamlencode({
ssh_authorized_keys = [tls_private_key.ssh_nomad_cluster.public_key_openssh]
packages = ["openssh-server", "haproxy"]
write_files = [
{ path = "/etc/certs.d/ca.pem", content = tls_self_signed_cert.nomad_cluster.cert_pem },
{ path = "/etc/certs.d/cert.pem", content = tls_locally_signed_cert.load_balancer.cert_pem },
{ path = "/etc/certs.d/cert.pem.key", content = tls_private_key.load_balancer.private_key_pem },
{
path = "/etc/haproxy/haproxy.cfg"
content = templatefile("config/haproxy.cfg", {
external_domain = var.external_domain
consul_servers = local.consul_servers
vault_servers = local.vault_servers
nomad_servers = local.nomad_servers
nomad_infra_clients = local.nomad_infra_clients
})
}
]
})
}
}
resource "lxd_instance" "load_balancer" {
name = local.load_balancer["name"]
image = "ubuntu:${var.ubuntu_version}"
profiles = [lxd_profile.nomad_cluster.name]
device {
name = "eth0"
type = "nic"
properties = {
network = lxd_network.nomad.name
"ipv4.address" = local.load_balancer["host"]
}
}
config = {
"cloud-init.user-data" = data.cloudinit_config.load_balancer.rendered
}
device {
name = "map_port_80"
type = "proxy"
properties = {
listen = "tcp:0.0.0.0:80"
connect = "tcp:127.0.0.1:80"
}
}
device {
name = "map_port_443"
type = "proxy"
properties = {
listen = "tcp:0.0.0.0:443"
connect = "tcp:127.0.0.1:443"
}
}
provisioner "remote-exec" {
connection {
host = self.ipv4_address
user = "ubuntu"
private_key = tls_private_key.ssh_nomad_cluster.private_key_openssh
}
inline = ["cloud-init status -w > /dev/null"]
}
}