Google Associate Cloud EngineerSetting up a cloud solution environmentMedium
A development team is using Cloud Shell to interact with their Google Cloud projects. They need to quickly switch their active project for `gcloud` commands without affecting other Cloud Shell sessions or local configurations. Which `gcloud` command should they use?
- A`gcloud auth application-default set-quota-project [PROJECT_ID]`
- B`gcloud config configurations activate [CONFIGURATION_NAME]`
- C`gcloud config set project [PROJECT_ID]`
- D`gcloud projects update [PROJECT_ID]`
Show answer & explanationAnswer & explanation
Correct answer: C. `gcloud config set project [PROJECT_ID]`
The `gcloud config set project [PROJECT_ID]` command is used to set the default project for the current `gcloud` session. This change is local to the current session and does not impact other Cloud Shell instances or global configurations.
Why the other options are wrong
- A. This command sets the project to be used for quota billing when using Application Default Credentials, which is different from setting the active project for general `gcloud` commands.
- B. This command activates an entire named configuration, which might include more than just the project and could affect other settings, making it less suitable for a 'quick switch' without affecting other settings.
- D. This command is used to update properties of an existing project, not to switch the active project for `gcloud`.
gcloud config set project
The `gcloud config set project [PROJECT_ID]` command sets the default project for the current `gcloud` CLI session.
- Affects only the current session.
- Useful for quickly switching between projects.
- Does not modify persistent configurations unless explicitly saved.
Memory trick: To 'set' your 'config' for a project, use `gcloud config set project`.