Question

Difficulty: MediumDeploying and Managing Compute Engine Virtual Machines

An engineer needs to configure a `gcloud` command to deploy a Compute Engine virtual machine named `batch-processor` in zone `us-central1-a`. The VM must run using a dedicated custom service account named `[email protected]` and must automatically execute a script stored on the local administrative machine named `setup.sh` upon first boot. Which of the following flags must be included in the `gcloud compute instances create` command? (Select TWO correct answers.)

  1. --metadata-from-file=startup-script=setup.shAnswer
  2. C
  3. D
    --metadata=startup-script-url=setup.sh

Answer

The command requires `[email protected]` to attach the identity of the custom service account, and `--metadata-from-file=startup-script=setup.sh` to read and upload the local bash script as the startup script.
To assign a custom service account identity and execute a local script file on startup, `gcloud compute instances create` requires `--service-account` to define the identity and `--metadata-from-file=startup-script=...` to load local file contents into the startup script metadata entry.

Step-by-Step Solution

1
Identify the flag required to attach a specific custom service account identity to a Compute Engine instance during creation.
The correct flag is `--service-account=EMAIL`.
Attaching a custom service account defines the IAM identity for applications running inside the VM.
2
Identify the flag required to pass a local script file as an instance startup script.
The correct flag is `--metadata-from-file=startup-script=LOCAL_FILE_PATH`.
The `--metadata-from-file` flag reads content from the local disk, whereas `--metadata=startup-script-url=...` expects a remote URL.

Key Concept

Deploying Compute Engine VMs with custom service accounts and local startup scripts via gcloud CLI
Estimated Time:1m 30s
Rate this question