0
0
GCPcloud~5 mins

Scripting with gcloud in GCP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of using gcloud in scripts?

gcloud is a command-line tool to manage Google Cloud resources. In scripts, it automates tasks like creating, updating, or deleting resources without manual clicks.

Click to reveal answer
beginner
How do you authenticate a script to use gcloud commands?

You use gcloud auth login for user authentication or gcloud auth activate-service-account --key-file=KEY.json to authenticate with a service account key file for scripts.

Click to reveal answer
beginner
What does the --quiet flag do in gcloud scripts?

The --quiet flag disables all interactive prompts, making scripts run without waiting for user input.

Click to reveal answer
intermediate
Why is it important to check the exit status of gcloud commands in scripts?

Checking exit status helps detect if a command succeeded or failed, so the script can handle errors or stop to avoid unwanted actions.

Click to reveal answer
intermediate
How can you capture the output of a gcloud command in a script?

You can capture output by assigning it to a variable using command substitution, for example: output=$(gcloud compute instances list --format=json).

Click to reveal answer
Which command authenticates a service account for scripting with gcloud?
Agcloud auth activate-service-account --key-file=KEY.json
Bgcloud auth login
Cgcloud config set project PROJECT_ID
Dgcloud init
What does the --quiet flag do when added to a gcloud command in a script?
ASkips authentication
BShows detailed logs
CRuns the command without any interactive prompts
DRuns the command in debug mode
How can you handle errors in a script using gcloud commands?
AIgnore errors and continue
BCheck the exit status after each command
CUse <code>gcloud error-check</code> command
DRestart the script automatically
Which format option helps get machine-readable output from gcloud commands?
A--format=json
B--verbose
C--quiet
D--interactive
What is a good practice when writing scripts with gcloud commands?
AAlways use interactive mode
BRun commands without authentication
CIgnore command outputs
DUse service account authentication and check command results
Explain how to authenticate and run a gcloud command in a script without user interaction.
Think about how scripts avoid prompts and authenticate automatically.
You got /3 concepts.
    Describe how to capture and use the output of a gcloud command inside a script.
    Consider how shell scripts store command results.
    You got /3 concepts.