Skip to content

Instantly share code, notes, and snippets.

@jayendra13
Created April 27, 2024 04:30
Show Gist options
  • Save jayendra13/9a0ae8a2359ab6f33fabc086de03ee4a to your computer and use it in GitHub Desktop.
Save jayendra13/9a0ae8a2359ab6f33fabc086de03ee4a to your computer and use it in GitHub Desktop.
gcloud helpers
# List all the VM for given project
gcloud compute instances list --format="text(name,zone.basename())"
# List all the VM for given project in table format with id
gcloud compute instances list --format="table(id, name,zone.basename())"
# List all the VM get only id for shell processing
gcloud compute instances list --format="csv[no-heading](id)"
# Get service account for given vm
gcloud compute instances describe test --zone us-west1-b --format='json(name,serviceAccounts)'
# Get the creator of VM by vm name
gcloud logging read 'resource.type="gce_instance" protoPayload.methodName:"compute.instances.insert" log_id("cloudaudit.googleapis.com/activity") protoPayload.request.name="test"' --format="list(protoPayload.response.user)"
# Get the creator of VM by vm id
gcloud logging read 'resource.type="gce_instance" protoPayload.methodName:"compute.instances.insert" log_id("cloudaudit.googleapis.com/activity") resource.labels.instance_id="YOUR_ID_HERE"' --format="list(protoPayload.response.user)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment