Question

Difficulty: MediumDeploying and Managing Compute Engine Virtual Machines

A cloud engineer needs to execute a gcloud CLI command to deploy a new Compute Engine VM instance named batch-processor. The instance must execute initialization tasks on startup using a shell script located on the local workstation at ./scripts/init.sh. Additionally, the instance must run under a custom user-managed service account named [email protected]. Which flags must be included in the gcloud compute instances create command to meet these requirements? (Select TWO.)

  1. --metadata-from-file=startup-script=./scripts/init.shAnswer
  2. C
    --startup-script=./scripts/init.sh
  3. D

Answer

The correct options are the flags using metadata from file for the startup script (--metadata-from-file=startup-script=./scripts/init.sh) and assigning the custom service account email ([email protected]).
To load a local script file as a startup script on a Compute Engine VM instance during provisioning, gcloud compute instances create requires the --metadata-from-file=startup-script=./scripts/init.sh flag. To assign a specific IAM service account identity to the VM instance, the --service-account flag must be passed with the service account's email address.

Step-by-Step Solution

1
Identify the flag required to pass a local file script to VM startup metadata.
The gcloud CLI uses --metadata-from-file=startup-script=<path> to upload the contents of a local script file into instance metadata.
Direct startup script strings are set via standard metadata, but reading directly from a local shell file requires the --metadata-from-file flag syntax.
2
Identify the flag required to specify the attached IAM service account identity.
The gcloud CLI uses --service-account=<email> to assign identity to the Compute Engine VM.
The service account flag specifies the service account identity, whereas the --scopes flag only defines API access scopes for that identity.

Key Concept

Compute Engine gcloud CLI VM creation flags for startup scripts and service account attachment
Rate this question