I've started something similar years ago as a dynamic gitlab runner (example pipeline): https://morph027.gitlab.io/pve-cloud-init-creator/
Quite complex, as custom userdata relies on snippet storage, which is not yet usable via the API (see https://bugzilla.proxmox.com/show_bug.cgi?id=2208)...