Proper use of cloud-init in profile config

Greetings all. I went to start tuning my LXD use by adding an SSH key to the ubuntu user via a custom profile. I basically followed the steps from the docs to create a profile called default-cloudinit like below:

config:
  # this was what I started with, but eventually I found
  # that it needed to be `user.user-data` to work...
  cloud-init.user-data: |
    #cloud-config
    users:
      - name: ubuntu
        ssh_authorized_keys:
          - ssh-ed25519 xxxxxxxxx
description: Default LXD profile with Cloud-init
devices:
  eth0:
    name: eth0
    nictype: macvlan
    parent: eth0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default-cloudinit
used_by: []

I then launched an instance with:

lxc launch ubuntu:20.04 test1 -p default-cloudinit

After much debugging (and deleting/recreating my container), I found that the cloud-init configuration in the profile would only be processed if I modified the config key from cloud-init.user-data to user.user-data. The docs seem to indicate using cloud-init.user-data. Am I missing something here or are the docs misleading me?

Thanks!

It depends on the image. LXD has introduced the new cloud-init.* config keys less than a year ago. I’d expect the Ubuntu 22.04 images to use that properly, but older images may not.

In such cases, the older name user.user-data should generally be more widely compatible as even newer images will look for the old name.

Okay, I could see that. I’m using the latest 20.04 image build, and the interesting aspect that I’ve noticed after expanding the cloud-init definition (past just the ssh_authorized_keys entry) is that other aspects for the ubuntu user (such as a sudo line) are being processed with the config key as cloud-init.user-data. But ssh_authorized_keys only seems to be applied when I’m using user.user-data. I think I need to look into more of the under-hood details of cloud-init here…

@Chad_Smith any idea?