Skip to content

Commit

Permalink
Merge pull request #945 from Itxaka/tf-0.12
Browse files Browse the repository at this point in the history
 Update terraform files for tf 0.12
  • Loading branch information
jordimassaguerpla authored Feb 6, 2020
2 parents beef55a + a091229 commit 6b2bb42
Show file tree
Hide file tree
Showing 42 changed files with 725 additions and 553 deletions.
110 changes: 63 additions & 47 deletions ci/infra/libvirt/lb-instances.tf
Original file line number Diff line number Diff line change
@@ -1,98 +1,107 @@
data "template_file" "lb_repositories" {
count = "${length(var.lb_repositories)}"
template = "${file("cloud-init/repository.tpl")}"
count = length(var.lb_repositories)
template = file("cloud-init/repository.tpl")

vars {
repository_url = "${element(values(var.lb_repositories), count.index)}"
repository_name = "${element(keys(var.lb_repositories), count.index)}"
vars = {
repository_url = element(values(var.lb_repositories), count.index)
repository_name = element(keys(var.lb_repositories), count.index)
}
}

data "template_file" "haproxy_apiserver_backends_master" {
count = "${var.masters}"
count = var.masters
template = "server $${fqdn} $${ip}:6443\n"

vars = {
fqdn = "${var.stack_name}-master-${count.index}.${var.dns_domain}"
ip = "${cidrhost(var.network_cidr, 512 + count.index)}"
ip = cidrhost(var.network_cidr, 512 + count.index)
}
}

data "template_file" "haproxy_gangway_backends_master" {
count = "${var.masters}"
count = var.masters
template = "server $${fqdn} $${ip}:32001\n"

vars = {
fqdn = "${var.stack_name}-master-${count.index}.${var.dns_domain}"
ip = "${cidrhost(var.network_cidr, 512 + count.index)}"
ip = cidrhost(var.network_cidr, 512 + count.index)
}
}

data "template_file" "haproxy_dex_backends_master" {
count = "${var.masters}"
count = var.masters
template = "server $${fqdn} $${ip}:32000\n"

vars = {
fqdn = "${var.stack_name}-master-${count.index}.${var.dns_domain}"
ip = "${cidrhost(var.network_cidr, 512 + count.index)}"
ip = cidrhost(var.network_cidr, 512 + count.index)
}
}

data "template_file" "lb_haproxy_cfg" {
template = "${file("cloud-init/haproxy.cfg.tpl")}"
template = file("cloud-init/haproxy.cfg.tpl")

vars {
apiserver_backends = "${join(" ", data.template_file.haproxy_apiserver_backends_master.*.rendered)}"
gangway_backends = "${join(" ", data.template_file.haproxy_gangway_backends_master.*.rendered)}"
dex_backends = "${join(" ", data.template_file.haproxy_dex_backends_master.*.rendered)}"
vars = {
apiserver_backends = join(
" ",
data.template_file.haproxy_apiserver_backends_master.*.rendered,
)
gangway_backends = join(
" ",
data.template_file.haproxy_gangway_backends_master.*.rendered,
)
dex_backends = join(
" ",
data.template_file.haproxy_dex_backends_master.*.rendered,
)
}
}

data "template_file" "lb_cloud_init_userdata" {
template = "${file("cloud-init/lb.tpl")}"
template = file("cloud-init/lb.tpl")

vars {
authorized_keys = "${join("\n", formatlist(" - %s", var.authorized_keys))}"
repositories = "${join("\n", data.template_file.lb_repositories.*.rendered)}"
username = "${var.username}"
password = "${var.password}"
ntp_servers = "${join("\n", formatlist (" - %s", var.ntp_servers))}"
vars = {
authorized_keys = join("\n", formatlist(" - %s", var.authorized_keys))
repositories = join("\n", data.template_file.lb_repositories.*.rendered)
username = var.username
password = var.password
ntp_servers = join("\n", formatlist(" - %s", var.ntp_servers))
}
}

resource "libvirt_volume" "lb" {
name = "${var.stack_name}-lb-volume"
pool = "${var.pool}"
size = "${var.disk_size}"
base_volume_id = "${libvirt_volume.img.id}"
pool = var.pool
size = var.disk_size
base_volume_id = libvirt_volume.img.id
}

resource "libvirt_cloudinit_disk" "lb" {
name = "${var.stack_name}-lb-cloudinit-disk"
pool = "${var.pool}"
pool = var.pool

user_data = "${data.template_file.lb_cloud_init_userdata.rendered}"
user_data = data.template_file.lb_cloud_init_userdata.rendered
}

resource "libvirt_domain" "lb" {
name = "${var.stack_name}-lb-domain"
memory = "${var.lb_memory}"
vcpu = "${var.lb_vcpu}"
cloudinit = "${libvirt_cloudinit_disk.lb.id}"
memory = var.lb_memory
vcpu = var.lb_vcpu
cloudinit = libvirt_cloudinit_disk.lb.id

cpu {
cpu = {
mode = "host-passthrough"
}

disk {
volume_id = "${libvirt_volume.lb.id}"
volume_id = libvirt_volume.lb.id
}

network_interface {
network_id = "${libvirt_network.network.id}"
network_id = libvirt_network.network.id
hostname = "${var.stack_name}-lb"
addresses = ["${cidrhost(var.network_cidr, 256)}"]
wait_for_lease = 1
addresses = [cidrhost(var.network_cidr, 256)]
wait_for_lease = true
}

graphics {
Expand All @@ -102,13 +111,16 @@ resource "libvirt_domain" "lb" {
}

resource "null_resource" "lb_wait_cloudinit" {
depends_on = ["libvirt_domain.lb"]
count = "${var.lbs}"
depends_on = [libvirt_domain.lb]
count = var.lbs

connection {
host = "${element(libvirt_domain.lb.*.network_interface.0.addresses.0, count.index)}"
user = "${var.username}"
password = "${var.password}"
host = element(
libvirt_domain.lb.*.network_interface.0.addresses.0,
count.index,
)
user = var.username
password = var.password
type = "ssh"
}

Expand All @@ -120,22 +132,25 @@ resource "null_resource" "lb_wait_cloudinit" {
}

resource "null_resource" "lb_push_haproxy_cfg" {
depends_on = ["null_resource.lb_wait_cloudinit"]
count = "${var.lbs}"
depends_on = [null_resource.lb_wait_cloudinit]
count = var.lbs

triggers = {
master_count = "${var.masters}"
master_count = var.masters
}

connection {
host = "${element(libvirt_domain.lb.*.network_interface.0.addresses.0, count.index)}"
user = "${var.username}"
host = element(
libvirt_domain.lb.*.network_interface.0.addresses.0,
count.index,
)
user = var.username
type = "ssh"
agent = true
}

provisioner "file" {
content = "${data.template_file.lb_haproxy_cfg.rendered}"
content = data.template_file.lb_haproxy_cfg.rendered
destination = "/tmp/haproxy.cfg"
}

Expand All @@ -146,3 +161,4 @@ resource "null_resource" "lb_push_haproxy_cfg" {
]
}
}

7 changes: 4 additions & 3 deletions ci/infra/libvirt/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
provider "libvirt" {
uri = "${var.libvirt_uri}"
uri = var.libvirt_uri
}

resource "libvirt_volume" "img" {
name = "${var.stack_name}-${basename(var.image_uri)}"
source = "${var.image_uri}"
pool = "${var.pool}"
source = var.image_uri
pool = var.pool
}

Loading

0 comments on commit 6b2bb42

Please sign in to comment.