terra-farm / terraform-provider-virtualbox

VirtualBox provider for Terraform
https://terra-farm.github.io/provider-virtualbox/
MIT License
322 stars 137 forks source link

Deprecate user_data #150

Open VoyTechnology opened 1 year ago

VoyTechnology commented 1 year ago

The user_data field doesn't work and unfortunately we should deprecate the field until it does.

Problem

At the moment the user_data is provided to the Virtualbox VM by setting extra data on the VM. This in itself is useless, as this needs to be read on the VM side with guest additions and then somehow then passed to cloud-init (this is the assumption for user_data support, I am not sure are there any other uses for user_data).

Short Term Solution

user_data field is deprecated, and all issues will be closed pointing at this one as it's clear it's broken and there is no need to have 10 of them open.

Long term solution

Bring back support for user_data, but this time make it work. One of the proposed solutions is to create an image out of the data and mount it. This is something we should explore. If we fail we will just remove user_data support completely.

Action Items

EvanCarroll commented 1 year ago

If VirtualBox were to spin up a webserver up on the 169.254.169.254 address to host cloud-init config files, and attach the booting machine into a vlan with only that other box. Then it would work?

netcarver commented 10 months ago

I managed to use cloud-localds to create a user_data.iso that can be mounted into the vm using the optical_disks option, allowing cloud-init to proceed with the user_data from the mounted image.

1. Outline user_data cloud-init file

Create /home/user/boxes/user_data and set to whatever you want. Minimal snippet to start...

#cloud-config
locale: en_GB.UTF-8
timezone: Europe/London
package_update: True
packages:
  - virtualbox-guest-utils
  - podman
  - btop
  - ncdu
  - duf

2. Create the user_data.iso for mounting into VMs

cd /home/user/boxes && cloud-localds user_data.iso user_data

Giving /home/user/boxes/user_data.iso.

3. Mount this .iso using optical_disks option

In the main.tf file, I added the iso as an optical disk;

resource "virtualbox_vm" "node" {
  name      = ...
  image     = "/home/user/boxes/jammy-server-cloudimg-amd64.ova"
  ...

  optical_disks = [ "/home/user/boxes/user_data.iso" ]

  network_adapter {
    ...
  }
}

Which successfully executes cloud-init as expected on the provisioned VMs.