Question

Difficulty: EasyEnabling and Managing Cloud Service APIs

You are setting up a new project environment and need to enable the Compute Engine API using the Google Cloud CLI (`gcloud`). Which of the following represents the correct sequence of steps to safely verify context, enable the API, and confirm activation?

  1. 1Set the current active Google Cloud project context using `gcloud config set project [PROJECT_ID]`.
  2. 2Check if the Compute Engine API is already active by running `gcloud services list --enabled`.
  3. 3Enable the Compute Engine service API by executing `gcloud services enable compute.googleapis.com`.
  4. 4Verify successful enablement by executing `gcloud services list --enabled --filter="NAME:compute.googleapis.com"`.

Answer

The correct sequence begins by targeting the proper project context with `gcloud config set project`, checking current enabled services with `gcloud services list --enabled`, enabling the specific service via `gcloud services enable compute.googleapis.com`, and finally verifying activation with a filtered `gcloud services list` command.
Enabling a service API requires selecting the target project first so that modifications affect the intended GCP resource. Inspecting existing enabled services before enabling and filtering the enabled list after enabling establishes standard operational hygiene for managing Service Usage in Google Cloud.

Step-by-Step Solution

1
Set active gcloud project context
CLI configuration points to the desired GCP project ID
Prevents enabling APIs in the wrong project or organization scope
2
Inspect currently enabled APIs
List of active services for the target project is displayed
Establishes baseline status of enabled APIs
3
Enable the target API service
Service Usage API processes the enablement request for `compute.googleapis.com`
Activates the required underlying GCP service capabilities
4
Filter and confirm enabled status
Confirmation that `compute.googleapis.com` appears in the enabled services list
Validates that enablement completed without error

Key Concept

Enabling Cloud Service APIs via gcloud CLI workflow
Rate this question