Tran Chien
Tran Chien

Reputation: 633

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.

Upvotes: 0

Views: 216

Answers (2)

Johannes Passing
Johannes Passing

Reputation: 2805

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.

Upvotes: 1

Tran Chien
Tran Chien

Reputation: 633

I managed to pass access_token directly from my app to the startup-script and use curl to invoke googleapis directly.

Upvotes: 0

Related Questions