From reading the cloud-init docs (https://cloudinit.readthedocs.io/en/latest/topics/modules.html#apt-configure), it appears that this user-data should add the Nodesource source and key for apt, and install Node v18:
apt:
sources:
nodejs:
source: deb https://deb.nodesource.com/node_18.x $RELEASE main
keyserver: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
packages:
- nodejs
The URLs do appear to reference the package and a key. However, cloud-init adds a .list file in /etc/apt/sources.list.d/, doesn't add a key file in /usr/share/keyrings/, and complains that
W: GPG error: https://deb.nodesource.com/node_18.x jammy InRelease: The following signatures couldn't be verified because the public
key is not available: NO_PUBKEY 1655A0AB68576280
E: The repository 'https://deb.nodesource.com/node_18.x jammy InRelease' is not signed.
and doesn't install Node.
When installing Node by writing an apt list file, the package reference looks like this:
deb [signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_18.x jammy main
I could put something like that on the source:
line, but what key file name would I reference?