google-cloud-platformgoogle-container-os

Container OS metadata `user-data` metadata


Is there a way to pass user-data flag as a remote script? Similar to startup-script-url ?

I have configured a yaml file using cloud-config and use --metadata-from-file user-data=config-basic.yaml flag to create a new VM with CoS.

I want to create VMs programmatically and a local file may not be accessible nor passing whole script content as user-data metadata property is feasible.

Option 1) Write cloud-config script as a shell script? Option 2) Find logic that invokes cloud-config and populate it with metadata and insert contents there. Option 3) A better option???

https://cloud.google.com/compute/docs/instances/startup-scripts/linux

gcloud compute instances create cos-vertex-gpu \
 --image cos-101-17162-40-34 \
--image-project cos-cloud \
--boot-disk-size 100 \
--machine-type n1-standard-4 \
--zone us-west1-a \
--metadata="google-logging-enabled=true,google-monitoring-enabled=true" \
--metadata-from-file user-data=config-basic.yaml \
--maintenance-policy=TERMINATE \
--accelerator=type=nvidia-tesla-t4,count=1

Solution

  • I was not able to find a way to pass a remote: cloud-config programmatically.

    I ended up re-writing my cloud-config as a shell script and pass it using startup-script-url