forked from c0dyhi11/packet-weaveworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-configure-bgp.tf
58 lines (50 loc) · 1.87 KB
/
04-configure-bgp.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
data "template_file" "interface_lo0" {
template = "${file("templates/lo_interface.tpl")}"
vars = {
floating_ip = "${packet_reserved_ip_block.cluster_ip.address}"
floating_netmask = "${packet_reserved_ip_block.cluster_ip.netmask}"
}
}
data "template_file" "bird_conf_template" {
count = "${var.master_count}"
template = "${file("templates/bird_conf.tpl")}"
vars = {
floating_ip = "${packet_reserved_ip_block.cluster_ip.address}"
floating_cidr = "${packet_reserved_ip_block.cluster_ip.cidr}"
private_ipv4 = "${element(packet_device.k8s_masters.*.network.2.address, count.index)}"
gateway_ip = "${element(packet_device.k8s_masters.*.network.2.gateway, count.index)}"
bgp_password = "${var.bgp_password}"
local_asn = "${var.bgp_asn}"
}
}
resource "null_resource" "configure_bird" {
count = "${var.master_count}"
connection {
type = "ssh"
user = "root"
private_key = "${file("~/.ssh/id_rsa")}"
host = "${element(packet_device.k8s_masters.*.access_public_ipv4, count.index)}"
}
provisioner "remote-exec" {
inline = [
"apt-get install bird",
"mv /etc/bird/bird.conf /etc/bird/bird.conf.old"
]
}
provisioner "file" {
content = "${element(data.template_file.bird_conf_template.*.rendered, count.index)}"
destination = "/etc/bird/bird.conf"
}
provisioner "file" {
content = "${data.template_file.interface_lo0.rendered}"
destination = "/etc/network/interfaces.d/lo0"
}
provisioner "remote-exec" {
inline = [
"sysctl net.ipv4.ip_forward=1",
"grep /etc/network/interfaces.d /etc/network/interfaces || echo 'source /etc/network/interfaces.d/*' >> /etc/network/interfaces",
"ifup lo:0",
"service bird restart"
]
}
}