Question

Difficulty: MediumDeploying and Managing Compute Engine Virtual Machines

A DevOps engineer is scripting the deployment of a Compute Engine instance using the `gcloud` CLI. The VM requires a local initialization script `./init.sh` to run at boot time and must run under an existing custom service account `[email protected]`. Which TWO `gcloud compute instances create` flags should be included in the command execution?

  1. --metadata-from-file=startup-script=./init.shAnswer
  2. C
    --startup-script=./init.sh
  3. D
    --iam-role=roles/editor

Answer

The correct options are `--metadata-from-file=startup-script=./init.sh` and `[email protected]`.
To provision a Compute Engine VM with a custom service account and a local startup script, two distinct `gcloud` flags are required: `--service-account` specifies the custom service account identity, and `--metadata-from-file=startup-script=...` loads the contents of the specified local file into the VM's metadata.

Step-by-Step Solution

1
Identify the flag required to pass a local startup script file during instance creation.
Determine that local file content must be loaded into instance metadata using `--metadata-from-file=startup-script=./init.sh`.
Compute Engine uses instance metadata to handle startup script execution, and local file contents must be read using the `--metadata-from-file` flag.
2
Identify the flag required to associate a custom service account with the Compute Engine instance.
Determine that `[email protected]` is used to attach the service account.
The `--service-account` flag explicitly assigns identity and associated credentials to the virtual machine instance.

Key Concept

Deploying Compute Engine Virtual Machines with custom service accounts and startup script metadata via gcloud CLI
Rate this question