Google PCA Manage and provision cloud infrastructure Practice Question
A developer needs to pass a startup script to a Compute Engine instance during creation. Which method should be used to ensure the script runs on first boot?
⚠ Common exam trap
A common mix-up: candidates confuse the nonexistent `--startup-script` flag with the correct `--metadata=startup-script=...` syntax, or assume that adding metadata after creation will trigger the script on the first boot.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use gcloud compute instances create with --metadata=startup-script=...
The `--metadata=startup-script=...` flag on `gcloud compute instances create` passes the script as instance metadata. Compute Engine automatically executes the value of the `startup-script` metadata key on every boot, including the first boot. This is the standard, documented method for providing a startup script at instance creation time.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use gcloud compute instances create with --metadata=startup-script=...
Why this is correct
The startup-script metadata key is read by the Compute Engine guest agent, which executes its value on first boot. Passing it via --metadata during instance creation satisfies the requirement that the script run at startup.
- ✗
Create a custom image with the script baked in.
Why it's wrong here
Baking the script into a custom image runs it whenever an instance boots from that image, including reboots, and requires image maintenance rather than passing the script at creation. It is tempting because images do embed configuration, but the scenario requires supplying the script during instance creation.
- ✗
Use gcloud compute instances add-metadata after creating the instance.
Why it's wrong here
Metadata added after creation only applies on a subsequent boot, so the first-boot script never runs; the startup-script metadata key must be supplied at instance creation. It tempts because add-metadata does set instance metadata, which is the correct mechanism when updating an existing instance's configuration.
- ✗
Use gcloud compute instances create with --startup-script flag.
Why it's wrong here
The gcloud command does not have a --startup-script flag; metadata is used instead.
Go deeper
Related to this question
Learn chapter
Google Kubernetes Engine (GKE)
Key term
Compute Engine
Compute Engine is Google Cloud's Infrastructure-as-a-Service (IaaS) offering that lets you create and run virtual machines on Google's infrastructure.
Key term
Startup script
A startup script is a file of commands or code that runs automatically when a cloud virtual machine starts up, allowing you to configure the system without manual logging in.
About these practice questions
One of 807 original PCA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCA practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCA exam.