0
0
GCPcloud~20 mins

Scripting with gcloud in GCP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
gcloud Scripting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding gcloud command output
You run the command gcloud compute instances list --filter="status=RUNNING" --format="value(name)". What is the output format you will get?
AA JSON array containing objects with instance names as keys.
BA YAML formatted list of instance names with their statuses.
CA table with columns showing instance names and statuses.
DA plain list of instance names, one per line, with no extra formatting.
Attempts:
2 left
💡 Hint
The --format="value(name)" flag outputs only the values of the 'name' field.
Configuration
intermediate
2:00remaining
Correct gcloud command to create a VM with a startup script
Which gcloud command correctly creates a Compute Engine VM named web-server in zone us-central1-a with a startup script located at startup.sh?
Agcloud compute instances create web-server --zone=us-central1-a --metadata-from-file startup-script=startup.sh
Bgcloud compute instances create web-server --zone=us-central1-a --startup-script=startup.sh
Cgcloud compute instances create web-server --zone=us-central1-a --metadata startup-script=$(cat startup.sh)
Dgcloud compute instances create web-server --zone=us-central1-a --metadata startup-script=startup.sh
Attempts:
2 left
💡 Hint
The startup script must be passed as a file using the correct metadata flag.
Architecture
advanced
3:00remaining
Automating multi-region deployment with gcloud scripting
You want to write a script that creates a Compute Engine instance named app-server in three different zones: us-east1-b, us-west1-a, and europe-west1-b. Which approach ensures the script runs efficiently and handles errors gracefully?
ARun the three commands in parallel without error checking to save time.
BRun a single <code>gcloud compute instances create</code> command with all three zones specified in one command.
CRun three separate <code>gcloud compute instances create</code> commands sequentially, checking the exit status after each and logging errors.
DCreate one instance and then copy it to other zones using <code>gcloud compute instances copy</code>.
Attempts:
2 left
💡 Hint
gcloud commands typically create one instance per command; error handling is important in scripts.
security
advanced
3:00remaining
Securing gcloud scripts with service accounts
You have a gcloud script that creates and deletes resources. To avoid using your personal credentials, which is the best practice to authenticate the script securely?
AUse a service account key file and activate it with <code>gcloud auth activate-service-account --key-file=KEY_FILE</code> before running the script.
BStore your personal gcloud credentials in the script and use <code>gcloud auth login</code> automatically.
CRun the script without authentication; gcloud will prompt for credentials each time.
DUse anonymous authentication to avoid storing any credentials.
Attempts:
2 left
💡 Hint
Service accounts provide non-personal credentials for automation.
Best Practice
expert
4:00remaining
Optimizing gcloud script for repeated resource creation
You have a gcloud script that creates a Compute Engine instance named test-vm. Running the script multiple times causes errors because the instance already exists. What is the best way to modify the script to avoid errors and ensure idempotent behavior?
AIgnore errors and run the create command every time; errors do not affect the script.
BUse <code>gcloud compute instances describe test-vm</code> to check if the instance exists, and create it only if it does not.
CAdd a command to delete the instance before creating it, regardless of its existence.
DRename the instance each time with a random suffix to avoid name conflicts.
Attempts:
2 left
💡 Hint
Idempotent scripts check resource existence before creation.