terraform-provider-libvirt icon indicating copy to clipboard operation
terraform-provider-libvirt copied to clipboard

Rework/redisign cloudinit iso-generation

Open MalloZup opened this issue 6 years ago • 9 comments

So this is issue is for improving the cloudinit design.

We find out currently that requiring mkisofs is not universal enough in different os ( some version of SLES/ and some debian lack on this pkg). Using also geniso was the same issue.

This issue is more about thinking on how we could redisign the iso generation part in more scalable/universal way.

I was thinking to use usb disk and dd. I think this could be possible and more universal.

But maybe other ways are possible

MalloZup avatar Oct 30 '18 11:10 MalloZup

How about using https://github.com/kdomanski/iso9660, do you see any immediate downside or roadblock?

moio avatar Nov 13 '19 21:11 moio

good point. I think i didn't check it but is a good link to look at. thx for re-opining :)

MalloZup avatar Nov 14 '19 09:11 MalloZup

For debian:

apt update && apt install xorriso && update-alternatives --install /usr/bin/mkisofs mkisofs /usr/bin/xorrisofs 10

CyberDomovoy avatar Feb 25 '20 22:02 CyberDomovoy

In the mean time https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=680949 has been fixed in debian unstable/testing so installing the genisoimage package should be enough

bigon avatar Feb 25 '20 23:02 bigon

thx

MalloZup avatar Feb 26 '20 09:02 MalloZup

Hi, we create our config isos with https://github.com/diskfs/go-diskfs

Example: https://gist.github.com/kstieger/66399edf56ca967b9ac232e6c438c4cd

kstieger avatar Mar 02 '20 19:03 kstieger

Hm, not sure if this is the right place to put this but using 0.7.1 I seem to get an infinite hang when generating the cloudinit disk using archlinux as the host to create a rocklylinux guest. I saw in the debug logs that I needed mkisofs however this doesnt seem to have resolved the issue, if this was brought into the application itself it might prevent weirdness like this.

As example here is a tiny snippet of a build reaching the 22 minute mark despite it only trying to create a single host: Where the cloud-init contents is literally "set a public key"

libvirt_cloudinit_disk.commoninit: Still creating... [22m11s elapsed]
libvirt_volume.rocky9: Still creating... [22m21s elapsed]
libvirt_cloudinit_disk.commoninit: Still creating... [22m21s elapsed]

main.tf

terraform {
  required_version = ">= 0.13"
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = "0.7.1"
    }
  }
}

# instance the provider
provider "libvirt" {
  uri = "qemu:///system"
}

# We fetch the latest ubuntu release image from their mirrors
resource "libvirt_volume" "rocky9" {
  name   = "rocky9"
  source = "https://download.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud.latest.x86_64.qcow2"
  format = "qcow2"
}

data "template_file" "user_data" {
  template = file("${path.module}/cloud_init.cfg")
}

data "template_file" "network_config" {
  template = file("${path.module}/network_config.cfg")
}

# for more info about paramater check this out
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r/cloudinit.html.markdown
# Use CloudInit to add our ssh-key to the instance
# you can add also meta_data field
resource "libvirt_cloudinit_disk" "commoninit" {
  name           = "commoninit.iso"
  user_data      = data.template_file.user_data.rendered
  network_config = data.template_file.network_config.rendered
}

# Create the machine
resource "libvirt_domain" "domain-rocky9" {
  name   = "rocky9-terraform"
  memory = "2048"
  vcpu   = 2

  cloudinit = libvirt_cloudinit_disk.commoninit.id

  network_interface {
    network_name   = "default"
    wait_for_lease = true
  }

  cpu {
    mode = "host-passthrough"
  }

  # IMPORTANT: this is a known bug on cloud images, since they expect a console
  # we need to pass it
  # https://bugs.launchpad.net/cloud-images/+bug/1573095
  console {
    type        = "pty"
    target_port = "0"
    target_type = "serial"
  }

  console {
    type        = "pty"
    target_type = "virtio"
    target_port = "1"
  }

  disk {
    volume_id = libvirt_volume.rocky9.id
  }

  graphics {
    type     = "vnc"
    autoport = true
  }
}

NHAS avatar Jun 13 '23 09:06 NHAS

Ah okay, terraform 1.5.0 is broken, terraform 1.4.6 is totally fine. This isnt an issue for here I'll open one directly.

NHAS avatar Jun 13 '23 21:06 NHAS