Logic of templating Ubuntu 20.04 without preseed configuration files


I am not exactly sure how I am supposed to use Packer with Ubuntu 20.04 if Canonical has given d-i (debian-installer/preseeding) up, so I’m trying to form a perspective on how to basically use Packer and then apply Terraform on that template.

So the question is simple: if Ubuntu 20.04 is supposed to work with cloud-init from the very beginning (which you can use by adding the information in the kernel command line: autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/), then how am I supposed to apply any configuration dynamically afterwards? The server needs to recreate its ssh-keys, I need to reconfigure the network for each new virtual machine and so on. But if cloud-init runs only once, how are you supposed to run it again? What would be a standard way of going around this problem?

The same premise can be found here, in the hashicorps’ documentation: https://registry.terraform.io/providers/Telmate/proxmox/latest/docs/guides/cloud_init

You would customise the template to however you wished with packer and then at the end you would generalise the image, removing naming, ip config etc / reset cloud-init (rm -rf /var/lib/cloud/instances), deleting its config etc, so it runs again.

Also to reset cloud-init (probably better)

sudo cloud-init clean

This will make it re-run on the next boot, resetting the ip, ssh keys etc.

Yeah, I’ve read this answer everywhere, and I’m not really sure why this is consistently given as a valid answer. This doesn’t work for me and I’ve seen many people complain about not being able to reset cloud-init. Probably because the scenario doesn’t occur that often.
What worked me, apart from cloud-init clean, was:

rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
cat << EOF > /etc/cloud/cloud.cfg.d/99-pve.cfg
datasource_list: [ConfigDrive, NoCloud]

Someone also suggested running this, but it worked for me without having to remove them:

rm -f /etc/netplan/00-installer-config.yaml
rm -f /etc/netplan/50-cloud-init.yaml


Moreover, the autoinstaller works differently than I originally thought:

"ip={{ user `vm_ip` }}::{{ user `vm_gateway` }}:{{ user `vm_netmask` }}::::{{ user `vm_dns` }} ",
"autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ",

This is what I’m doing with packer (where you can replace your variables with the corresponding values, of course).
This is based on: