Search code examples
google-compute-enginecloud-init

running cloud init script in gce


Is it possible to provide cloud-init script for VM instance on ubuntu in GCE? i.e. to run something like

gcloud compute instances create my1 --image ubuntu-1404-trusty-v20150316 --metadata-from-file startup-script=my.cloudconfig

Solution

  • In 2022, Ubuntu images in GCE comes with cloud-init. Setting a user-data instance metadata lets cloud-init see and interpret it.

    // for example the projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20220810 OS image.

    However I think the command OP demonstrated is startup-script, which is a bash script executed by some GCE-specific service like google-startup-script, and have little to do with cloud-init.

    (Not every distribution has preinstalled cloud-init. Debian does not.)