A system administrator is writing a deployment script using the Google Cloud CLI (`gcloud`) to launch non-critical stateless batch processing Virtual Machine instances on Compute Engine. The VM instances must execute a bash initialization script located on the local disk at `./scripts/init.sh` upon first boot and execute using a dedicated custom IAM service account named `[email protected]`. Which TWO `gcloud compute instances create` flags must be used to meet these requirements?
- --service-account=batch-runner@my-project.iam.gserviceaccount.comAnswer
- --metadata-from-file=startup-script=./scripts/init.shAnswer
- C
- D--metadata=startup-script=./scripts/init.sh
Answer
The deployment command must include `--service-account=batch-runner@my-project.iam.gserviceaccount.com` to attach the custom IAM service account identity and `--metadata-from-file=startup-script=./scripts/init.sh` to read and load the local shell script into the VM metadata startup key.
To provision a Compute Engine instance attached to a custom service account and execute a local initialization script on startup, `gcloud compute instances create` requires two specific flags: `--service-account` to define the IAM identity, and `--metadata-from-file` with the `startup-script` key to read the local script contents into the VM metadata.
Step-by-Step Solution
Key Concept
Compute Engine gcloud CLI flags for identity binding and startup script configuration