OpenShift 4 Installation using libvirt & terraform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

78 lines
2.4 KiB

resource "libvirt_cloudinit_disk" "lb_cloudinit" {
name = "${local.lb_name}-cloudinit.iso"
user_data = data.template_file.lb_user_data.rendered
network_config = data.template_file.lb_network_config.rendered
pool = var.pool_name
}
data "template_file" "lb_user_data" {
template = file("${path.module}/templates/lb/cloud-init.cfg")
vars = {
haproxy_cfg = templatefile("${path.module}/templates/lb/haproxy.cfg", {
master_nodes = { for i in libvirt_domain.master : i.name => i.network_interface.0.addresses[0] },
worker_nodes = { for i in libvirt_domain.worker : i.name => i.network_interface.0.addresses[0] },
bootstrap_nodes = { for i in libvirt_domain.bootstrap : i.name => i.network_interface.0.addresses[0] }
})
}
}
data "template_file" "lb_network_config" {
template = file("${path.module}/templates/lb/network-config.cfg")
vars = {
ip = cidrhost(var.network_ip_range, 4)
dns = cidrhost(var.network_ip_range, 1)
gw = cidrhost(var.network_ip_range, 1)
}
}
resource "libvirt_volume" "lb_disk" {
name = "${local.lb_name}.${var.volume_format}"
format = var.volume_format
pool = var.pool_name
base_volume_name = "${var.centos_image}.${var.volume_format}"
size = var.lb_disk_size
}
resource "libvirt_domain" "lb" {
name = local.lb_name
vcpu = var.lb_vcpu
memory = var.lb_memory_size
cloudinit = libvirt_cloudinit_disk.lb_cloudinit.id
autostart = false
qemu_agent = true
cpu = {
mode = "host-passthrough"
}
disk {
volume_id = libvirt_volume.lb_disk.id
}
# Makes the tty0 available via `virsh console`
console {
type = "pty"
target_port = "0"
}
network_interface {
network_id = libvirt_network.ocp_net.id
addresses = [cidrhost(var.network_ip_range, 4)]
hostname = "lb"
# When creating the domain resource, wait until the network interface gets
# a DHCP lease from libvirt, so that the computed IP addresses will be
# available when the domain is up and the plan applied.
wait_for_lease = true
}
network_interface {
bridge = var.external_ifname
mac = var.external_mac_address
# When creating the domain resource, wait until the network interface gets
# a DHCP lease from libvirt, so that the computed IP addresses will be
# available when the domain is up and the plan applied.
wait_for_lease = true
}
}