diff --git a/ci/infra/libvirt/lb-instances.tf b/ci/infra/libvirt/lb-instances.tf index 71b17f6ede..9bce9a2c16 100644 --- a/ci/infra/libvirt/lb-instances.tf +++ b/ci/infra/libvirt/lb-instances.tf @@ -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 { @@ -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" } @@ -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" } @@ -146,3 +161,4 @@ resource "null_resource" "lb_push_haproxy_cfg" { ] } } + diff --git a/ci/infra/libvirt/main.tf b/ci/infra/libvirt/main.tf index 3745785d39..48787ca2c1 100644 --- a/ci/infra/libvirt/main.tf +++ b/ci/infra/libvirt/main.tf @@ -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 } + diff --git a/ci/infra/libvirt/master-instance.tf b/ci/infra/libvirt/master-instance.tf index 93942c531a..78e8a3f220 100644 --- a/ci/infra/libvirt/master-instance.tf +++ b/ci/infra/libvirt/master-instance.tf @@ -1,92 +1,92 @@ data "template_file" "master_repositories" { - template = "${file("cloud-init/repository.tpl")}" - count = "${length(var.repositories)}" + template = file("cloud-init/repository.tpl") + count = length(var.repositories) - vars { - repository_url = "${element(values(var.repositories), count.index)}" - repository_name = "${element(keys(var.repositories), count.index)}" + vars = { + repository_url = element(values(var.repositories), count.index) + repository_name = element(keys(var.repositories), count.index) } } data "template_file" "master_register_scc" { - template = "${file("cloud-init/register-scc.tpl")}" - count = "${var.caasp_registry_code == "" ? 0 : 1}" + template = file("cloud-init/register-scc.tpl") + count = var.caasp_registry_code == "" ? 0 : 1 - vars { - caasp_registry_code = "${var.caasp_registry_code}" + vars = { + caasp_registry_code = var.caasp_registry_code } } data "template_file" "master_register_rmt" { - template = "${file("cloud-init/register-rmt.tpl")}" - count = "${var.rmt_server_name == "" ? 0 : 1}" + template = file("cloud-init/register-rmt.tpl") + count = var.rmt_server_name == "" ? 0 : 1 - vars { - rmt_server_name = "${var.rmt_server_name}" + vars = { + rmt_server_name = var.rmt_server_name } } data "template_file" "master_commands" { - template = "${file("cloud-init/commands.tpl")}" - count = "${join("", var.packages) == "" ? 0 : 1}" + template = file("cloud-init/commands.tpl") + count = join("", var.packages) == "" ? 0 : 1 - vars { - packages = "${join(", ", var.packages)}" + vars = { + packages = join(", ", var.packages) } } data "template_file" "master-cloud-init" { - template = "${file("cloud-init/common.tpl")}" - - vars { - authorized_keys = "${join("\n", formatlist(" - %s", var.authorized_keys))}" - repositories = "${join("\n", data.template_file.master_repositories.*.rendered)}" - register_scc = "${join("\n", data.template_file.master_register_scc.*.rendered)}" - register_rmt = "${join("\n", data.template_file.master_register_rmt.*.rendered)}" - commands = "${join("\n", data.template_file.master_commands.*.rendered)}" - username = "${var.username}" - password = "${var.password}" - ntp_servers = "${join("\n", formatlist (" - %s", var.ntp_servers))}" + template = file("cloud-init/common.tpl") + + vars = { + authorized_keys = join("\n", formatlist(" - %s", var.authorized_keys)) + repositories = join("\n", data.template_file.master_repositories.*.rendered) + register_scc = join("\n", data.template_file.master_register_scc.*.rendered) + register_rmt = join("\n", data.template_file.master_register_rmt.*.rendered) + commands = join("\n", data.template_file.master_commands.*.rendered) + username = var.username + password = var.password + ntp_servers = join("\n", formatlist(" - %s", var.ntp_servers)) } } resource "libvirt_volume" "master" { name = "${var.stack_name}-master-volume-${count.index}" - pool = "${var.pool}" - size = "${var.disk_size}" - base_volume_id = "${libvirt_volume.img.id}" - count = "${var.masters}" + pool = var.pool + size = var.disk_size + base_volume_id = libvirt_volume.img.id + count = var.masters } resource "libvirt_cloudinit_disk" "master" { # needed when 0 master nodes are defined - count = "${var.masters}" + count = var.masters name = "${var.stack_name}-master-cloudinit-disk-${count.index}" - pool = "${var.pool}" - user_data = "${data.template_file.master-cloud-init.rendered}" + pool = var.pool + user_data = data.template_file.master-cloud-init.rendered } resource "libvirt_domain" "master" { - count = "${var.masters}" + count = var.masters name = "${var.stack_name}-master-domain-${count.index}" - memory = "${var.master_memory}" - vcpu = "${var.master_vcpu}" - cloudinit = "${element(libvirt_cloudinit_disk.master.*.id, count.index)}" - depends_on = ["libvirt_domain.lb"] + memory = var.master_memory + vcpu = var.master_vcpu + cloudinit = element(libvirt_cloudinit_disk.master.*.id, count.index) + depends_on = [libvirt_domain.lb] - cpu { + cpu = { mode = "host-passthrough" } disk { - volume_id = "${element(libvirt_volume.master.*.id, count.index)}" + volume_id = element(libvirt_volume.master.*.id, count.index) } network_interface { - network_id = "${libvirt_network.network.id}" + network_id = libvirt_network.network.id hostname = "${var.stack_name}-master-${count.index}" - addresses = ["${cidrhost(var.network_cidr, 512 + count.index)}"] - wait_for_lease = 1 + addresses = [cidrhost(var.network_cidr, 512 + count.index)] + wait_for_lease = true } graphics { @@ -96,13 +96,16 @@ resource "libvirt_domain" "master" { } resource "null_resource" "master_wait_cloudinit" { - depends_on = ["libvirt_domain.master"] - count = "${var.masters}" + depends_on = [libvirt_domain.master] + count = var.masters connection { - host = "${element(libvirt_domain.master.*.network_interface.0.addresses.0, count.index)}" - user = "${var.username}" - password = "${var.password}" + host = element( + libvirt_domain.master.*.network_interface.0.addresses.0, + count.index, + ) + user = var.username + password = var.password type = "ssh" } @@ -114,13 +117,16 @@ resource "null_resource" "master_wait_cloudinit" { } resource "null_resource" "master_reboot" { - depends_on = ["null_resource.master_wait_cloudinit"] - count = "${var.masters}" + depends_on = [null_resource.master_wait_cloudinit] + count = var.masters provisioner "local-exec" { environment = { - user = "${var.username}" - host = "${element(libvirt_domain.master.*.network_interface.0.addresses.0, count.index)}" + user = var.username + host = element( + libvirt_domain.master.*.network_interface.0.addresses.0, + count.index, + ) } command = <