A cloud engineer needs to deploy a Compute Engine virtual machine instance that automatically executes a bash initialization script stored in a private Cloud Storage bucket upon booting. The VM must adhere to the principle of least privilege using a custom service account. Arrange the required administrative steps in the correct chronological sequence from first to last.
- 1Create a custom IAM service account specifically for the virtual machine workload.
- 2Grant the Storage Object Viewer role (roles/storage.objectViewer) to the custom service account on the bucket hosting the script.
- 3Upload the bash initialization script to the designated Cloud Storage bucket path.
- 4Run gcloud compute instances create specifying --service-account, --scopes=https://www.googleapis.com/auth/cloud-platform, and --metadata=startup-script-url.
- 5Execute gcloud compute instances get-serial-port-output to review console output and verify successful script execution.
Answer
The correct sequence of steps is: 1) Create the custom service account, 2) Grant the service account Storage Object Viewer permissions on the script bucket, 3) Upload the initialization script to Cloud Storage, 4) Deploy the VM with gcloud using the service account and startup-script-url metadata flags, and 5) Verify script execution logs via the serial port output.
The correct procedural order ensures identity creation and resource authorization occur before instance provisioning. First, creating the custom service account establishes a dedicated identity. Second, assigning the Storage Object Viewer IAM role on the bucket grants the necessary read permission. Third, staging the script file in Cloud Storage ensures the asset exists. Fourth, invoking gcloud compute instances create attaches the service account with --scopes=cloud-platform and supplies the --metadata=startup-script-url flag. Finally, retrieving serial port output validates that the startup script completed without error.
Step-by-Step Solution
Key Concept
Deploying Compute Engine VMs with Custom Service Accounts and Cloud Storage Startup Scripts
Estimated Time:2m 0s