Soru

Zorluk: OrtaProgrammatic GCP Interaction via SDK, CLI, and APIs

A cloud administrator regularly manages infrastructure across separate development, staging, and production Google Cloud projects from a single workstation using the gcloud CLI. Currently, the administrator manually re-authenticates or overrides environment variables whenever switching target environments, which increases the risk of executing administrative commands against the wrong project. Which approach aligns with Google Cloud best practices for managing and switching between multiple environment settings cleanly when using the gcloud CLI?

  1. Create separate named gcloud configurations for each environment using gcloud config configurations create, define project and account settings within each configuration, and activate the required profile using gcloud config configurations activate.Cevap
  2. B
    Generate long-lived JSON service account key files for each project and write a wrapper shell script that dynamically exports GOOGLE_APPLICATION_CREDENTIALS pointing to the respective key file prior to running gcloud commands.
  3. C
    Assign the primitive Owner IAM role to the administrator's personal account across all target projects so that gcloud commands automatically inherit administrative context without explicitly defining configurations.
  4. D
    Perform all resource changes for staging and production manually via the Google Cloud Console, reserving gcloud CLI usage exclusively for the local development environment.

Cevap

Create and activate separate named gcloud configurations for each target project environment using the gcloud config configurations command group.
The gcloud CLI provides native support for multiple named configurations via `gcloud config configurations`. Each named configuration maintains its own set of properties, including default project ID, active user account, region, and zone. Activating a specific named configuration instantly switches the active operational context, preventing accidental execution against unintended projects without requiring static credential files.

Adım Adım Çözüm

1
Identify the requirement for isolated, reproducible CLI environment contexts.
Recognize that managing multiple Google Cloud projects requires switching gcloud settings like default project, region, zone, and authentication identity.
Manual overrides via environment variables or continuous re-authentication lead to configuration errors and operational risk.
2
Evaluate the native gcloud CLI features designed for multi-environment context management.
Determine that `gcloud config configurations` provides named profile management for distinct environment settings.
Named configurations isolate settings into discrete profiles that can be created, configured, and activated on demand.
3
Select the correct sequence of gcloud configuration management commands.
Use `gcloud config configurations create <name>` to establish profiles for development, staging, and production, and `gcloud config configurations activate <name>` to switch contexts safely.
This avoids downloading static service account keys, maintains security best practices, and prevents accidental operations in the wrong project environment.

Anahtar Kavram

gcloud Named Configurations for Environment Management
Bu soruyu puanla