Skip to content

Commit

Permalink
Add support for Leap Micro and combustion
Browse files Browse the repository at this point in the history
In order to support leap micro we need combustion support in the libvirt
provider. This requires this pull request:

dmacvicar/terraform-provider-libvirt#1068
  • Loading branch information
cbosdo committed Feb 12, 2024
1 parent 211dc54 commit 0820537
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend_modules/libvirt/base/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ locals {
slemicro54-ign = "${var.use_mirror_images ? "http://${var.mirror}" : "http://download.opensuse.org"}/repositories/systemsmanagement:/sumaform:/images:/microos/images_54/SLE-Micro.x86_64-sumaform.qcow2"
slemicro55o = "${var.use_mirror_images ? "http://${var.mirror}" : "http://download.opensuse.org"}/repositories/systemsmanagement:/sumaform:/images:/microos/images_55/SLE-Micro.x86_64-sumaform.qcow2"
suma43VM-ign = "${var.use_mirror_images ? "http://${var.mirror}" : "http://download.suse.de"}/ibs/Devel:/Galaxy:/Manager:/4.3/images/SUSE-Manager-Server.x86_64-KVM.qcow2"
leapmicro55o = "${var.use_mirror_images ? "http://${var.mirror}" : "https://download.opensuse.org"}/distribution/leap-micro/5.5/appliances/openSUSE-Leap-Micro.x86_64-Default-qcow.qcow2"
}
pool = lookup(var.provider_settings, "pool", "default")
network_name = lookup(var.provider_settings, "network_name", "default")
Expand Down
24 changes: 24 additions & 0 deletions backend_modules/libvirt/host/combustion
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# combustion: network

# Redirect output to the console
exec > >(exec tee -a /dev/tty0) 2>&1

# Set linux as password for root
echo 'root:$6$3aQC9rrDLHiTf1yR$NoKe9tko0kFIpu0rQ2y/OzOOtbVvs0Amr2bx0T4cGf6aq8PG74EmVy8lSDJdbLVVFpOSzwELWyReRCiPHa7DG0' | chpasswd -e

# Add a public ssh key and enable sshd
systemctl enable sshd.service

# Add the GPG keys
${ gpg_keys }

# Add repositories
zypper ar https://download.opensuse.org/repositories/systemsmanagement:/Uyuni:/Master:/ContainerUtils/openSUSE_Leap_Micro_5.5/ container_utils

# Install vim
zypper --non-interactive install bash-completion mgradm mgrctl mgradm-bash-completion mgrctl-bash-completion podman netavark aardvark-dns qemu-guest-agent salt-minion avahi

# Leave a marker
echo "Configured with combustion" > /etc/issue.d/combustion

26 changes: 23 additions & 3 deletions backend_modules/libvirt/host/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ locals {
manufacturer = lookup(var.provider_settings, "manufacturer", "Intel")
product = lookup(var.provider_settings, "product", "Genuine")
x86_64_v2_images = ["almalinux9o", "libertylinux9o", "oraclelinux9o", "rocky9o"]
combustion_images = ["leapmicro55o"]
gpg_keys = [
for key in fileset("salt/default/gpg_keys/", "*.key"): {
path = "/etc/gpg_keys/${key}"
Expand All @@ -12,6 +13,8 @@ locals {
permissions = "0700"
}
]

combustion = contains(local.combustion_images, var.image)
provider_settings = merge({
memory = 1024
vcpu = 1
Expand Down Expand Up @@ -40,8 +43,8 @@ locals {
var.provider_settings,
contains(var.roles, "virthost") ? { cpu_model = "host-passthrough", xslt = file("${path.module}/virthost.xsl") } : {},
contains(var.roles, "pxe_boot") ? { xslt = templatefile("${path.module}/pxe_boot.xsl", { manufacturer = local.manufacturer, product = local.product }) } : {})
cloud_init = length(regexall("o$", var.image)) > 0
ignition = length(regexall("-ign$", var.image)) > 0
cloud_init = length(regexall("o$", var.image)) > 0 && !contains(local.combustion_images, var.image)
ignition = length(regexall("-ign$", var.image)) > 0
}

data "template_file" "user_data" {
Expand All @@ -65,6 +68,22 @@ data "template_file" "network_config" {
}
}

data "template_file" "combustion" {
template = file("${path.module}/combustion")
vars = {
gpg_keys = join("\n", [for key in local.gpg_keys :
"mkdir -p `dirname ${key.path}` && echo ${key.content} | base64 -d >${key.path} && rpm --import ${key.path}"
])
}
}

resource "libvirt_combustion" "combustion_disk" {
name = "${local.resource_name_prefix}${var.quantity > 1 ? "-${count.index + 1}" : ""}-combustion-disk"
pool = var.base_configuration["pool"]
content = data.template_file.combustion.rendered
count = local.combustion ? var.quantity : 0
}

data "template_file" "ignition" {
template = file("${path.module}/config.ign")
}
Expand Down Expand Up @@ -134,7 +153,8 @@ resource "libvirt_domain" "domain" {
}

cloudinit = length(libvirt_cloudinit_disk.cloudinit_disk) == var.quantity ? libvirt_cloudinit_disk.cloudinit_disk[count.index].id : null
coreos_ignition = length(libvirt_ignition.ignition_disk) == var.quantity ? libvirt_ignition.ignition_disk[count.index].id : null
coreos_ignition = length(libvirt_ignition.ignition_disk) == var.quantity ? libvirt_ignition.ignition_disk[count.index].id : length(libvirt_combustion.combustion_disk) == var.quantity ? libvirt_combustion.combustion_disk[count.index].id : null
fw_cfg_name = local.combustion ? "opt/org.opensuse.combustion/script" : null

dynamic "network_interface" {
for_each = slice(
Expand Down
2 changes: 1 addition & 1 deletion modules/server_containerized/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
variable "images" {
default = {
"head" = "slemicro55o"
"uyuni-master" = "opensuse155o"
"uyuni-master" = "leapmicro55o"
"uyuni-released" = "opensuse155o"
"uyuni-pr" = "opensuse155o"
}
Expand Down

0 comments on commit 0820537

Please sign in to comment.