{ claus.conrad }

Create a FreeBSD GCE instance with salt-cloud

đź“… Apr 16, 2016
⌛ 2 minutes

When creating a Google Compute Engine instance from a publicly shared image which is not in your own project nor one of the default projects - such as FreeBSD - the image-project can be specified on the gcloud command line. Here's how to do the same when using salt-cloud instead of gcloud:

  • Assuming we have a working command line such as this:

    gcloud compute instances create my-freebsd-host --image freebsd-10-3-release-amd64 --image-project=freebsd-org-cloud-dev
    
  • First we have to find the URI of the public image:

    gcloud compute images list --project freebsd-org-cloud-dev --uri --regexp freebsd-10-3-release-amd64
    

    …which gives the following URI in this case:

    https://www.googleapis.com/compute/v1/projects/freebsd-org-cloud-dev/global/images/freebsd-10-3-release-amd64

  • Now the URI can be used in a salt-cloud profile instead of the image name, for example:

    sudo nano /etc/salt/cloud.profiles.d/my-freebsd-host.conf
    
    my-freebsd-host:  
    image: "https://www.googleapis.com/compute/v1/projects/freebsd-org-cloud-dev/global/images/freebsd-10-3-release-amd64"
    size: n1-standard-2  
    location: europe-west1-b  
    network: default  
    provider: gce  
    ssh_username: freebsd  
    

Note to self: remember to escape the URI string using quotation marks ;-)

Summary

When an instance is created from an image using either gcloud compute instance create or salt-cloud -p profile create, both utilities search for the image in the same project as the instance as well as the “well-known image projects”, which are “centos-cloud, coreos-cloud, debian-cloud, google-containers, opensuse-cloud, rhel-cloud, suse-cloud, ubuntu-os-cloud, windows-cloud”.

gcloud let’s you use images from other projects by specifying the --image-project parameter, while salt-cloud does not (presumably because libcloud does not support it either, this Apache library is used by salt-cloud under the hood). However, by using gcloud to find the URI of the public image we want to use, we can get salt-cloud to use any publicly available image for our instances.

Kudos to Agam for pointing me at the freebsd-org-cloud-dev image repository in the first place.