I'm working on several gcloud projects and I'm tired of having to type out --project XYZ
every time I need to call a command, or worse having the command execute on the wrong project if I forget to add that in.
Yes, by using gcloud configurations together with direnv.
Create a configuration (this will also activate it):
gcloud config configurations create <cool_new_config>
gcloud config set project <project>
Install direnv
. Hook it into your shell. With bash I used ~/.bash_profile
instead of directed ~/.bashrc
.
Navigate to the project folder where you want the switch to occur.
export CLOUDSDK_ACTIVE_CONFIG_NAME=<cool_new_config>
direnv allow
Verify functionality:
gcloud config configurations list
Optional: rebuild the rest of the configuration
gcloud config configurations list
gcloud config configurations describe <default>
gcloud auth login
gcloud config set compute/region <us-central1>
gcloud config set compute/zone <us-central1-a>