Google Associate Cloud EngineerSetting up a cloud solution environmentMedium
A developer is using Cloud Shell to interact with their Google Cloud projects. They frequently switch between a 'development' project and a 'staging' project. To avoid typing `—project [PROJECT_ID]` with every command, they want to quickly switch between these two projects as their default. Which `gcloud` command, combined with a specific configuration feature, would best achieve this?
- A`gcloud projects update [PROJECT_ID] --default`
- B`gcloud config configurations create [CONFIG_NAME]` and then `gcloud config set project [PROJECT_ID]`
- C`gcloud config set project [PROJECT_ID]` with `gcloud config configurations activate`
- D`gcloud config set project [PROJECT_ID]` and then `gcloud auth login`
Show answer & explanationAnswer & explanation
Correct answer: C. `gcloud config set project [PROJECT_ID]` with `gcloud config configurations activate`
Named configurations allow users to save different sets of `gcloud` properties, including the default project. You create separate configurations (e.g., for 'dev' and 'staging'), set the project within each, and then use `gcloud config configurations activate` to quickly switch between them.
Why the other options are wrong
- A. There is no `gcloud projects update --default` command. Project properties are set via `gcloud config set` or directly in commands.
- B. While `gcloud config configurations create` is part of the process, it only creates an empty configuration. You still need to set the project within it using `gcloud config set project` and then activate it.
- D. `gcloud auth login` is for authentication and doesn't directly manage project switching for default contexts. `gcloud config set project` alone only changes the current default without saving a named configuration.
gcloud Named Configurations
Named configurations in `gcloud` allow users to define and switch between multiple sets of `gcloud` properties (like default project, account, region), streamlining workflows for different environments or projects.
- Store different `gcloud` settings.
- Activated using `gcloud config configurations activate`.
- Useful for switching between projects or accounts.
Memory trick: Configure your named settings, then activate to switch projects with ease.