Search code examples
google-cloud-platformgoogle-compute-enginemetadatagcloud

How to add labels or metadata to GCE Instance from within the instance itself?


I need a way to list instances and startup scripts executing status (installing, preparing, done, ...).

labels and metadata are returned via instances.list result while console output require additional requests instance.describe for each instance.

However, when I use gcloud from within the instance itself, it throw error

startup-script: WARNING: Could not open the configuration file: [/root/.config/gcloud/configurations/config_default].
startup-script: ERROR: (gcloud.compute.instances.add-labels) You do not currently have an active account selected.

Solution

  • To report the status of startup scripts, consider using guest attributes instead:

    Guest attributes are a specific type of custom metadata that your applications can write to while running on your virtual machine (VM) instance. Any application or user on your VM instance can both read and write data to these guest attribute metadata values.

    You can think of guest attributes as the complement to metadata: While metadata lets you pass data to the guest, guest attributes are a way to let the guest pass data (such as status information) back.