Where does hostname.tpl come from?

take a look here

or at @simos’s blogs here https://blog.simos.info/how-to-preconfigure-lxd-containers-with-cloud-init/

But in reality the method with cloud-config is not very reliable for daily business. One workaround I figured out is to create a container from an image of your choice, configure it with a minimum of your needs and stop the container. Then copy it for a new container like »lxc copy container newcontainer«. Both containers are not running. Next do a »zfs list« to get your containers-storage place and »zfs mount container-stroage/newcontainer«. Now you can copy a prepared “interfaces”-file into the newcontainer in “/var/snap/lxd/common/lxd/storage-pools/default/containers/newcontainer/etc/network/” directly. This done you can start the new container and it will be up with the new ip-address .
Afterwards you can install &| configure your newcontainer by a script using i.e.

lxc exec – sh -c “cd /tmp”