Automating tasks with gcloud
Modifying output and behavior
- gcloud tool offers many configuration properties and global flags to customize user experience and modify behavior
| Global flags |
Description |
| –quiet |
Disable prompts |
| –log-http |
Record all network requests & responses |
| –verbosity <LEVEL> |
one of critical, debug, error, info, warningg none |
| –format |
Modify the output format for the command |
| –flatten |
Modifies the command outputt by separiting nested lists into distinct elements |
| List-Specific tags |
Description |
| –filter <Expression> |
Filter list results based on given expression |
| –limit <LIMIT> |
Limit number of results |
| –sort-by [FIELD, ..] |
One or more fields to sort results by |
- Lets use some of the expressions
gcloud services list --available
gcloud services list --available --format="json"
gcloud services list --format="table[box, title= 'Services List'](name, state)"

gcloud compute zones list --format="csv(name,region)"
gcloud compute networks subnets list --network=default --filter="region:(us-west1 us-central1)" --format=json
gcloud compute networks subnets list --format="json" --filter="name=default AND region ~ us-central1"
Sample Shell Script to iterate through vm instances
- Shell script to stop all vm instances
- Refer Here for the script
- Exercise: Modify the script to stop the vms only having specific labels
Like this:
Like Loading...