Post

Manage Multiple gcloud accounts in CLI

Manage Multiple gcloud accounts

If your organisation has multiple gcloud accounts or you want to manage both your company and your personal gcloud account using the CLI you could follow the below steps

1. List the configurations

The below command would list the current configurations available. You could delete the ones which are not needed

1
gcloud config configurations list

2. Create new config

Below command would create a new organisation ‘org2’ and makes it the default.

1
gcloud config configurations create org2

3. Authorise the new org

Once the new configuration is created, enter the below command which would open up the browser. Use your credentials for the new organisation or personal account.

1
gcloud auth login

4. Choose Project ID

Once the authorisation is completed, you would be receive a success message and it would also give you the option to choose the project. Enter the below command by replacing PROJECT_ID with your project ID.

1
gcloud config set project PROJECT_ID

5. Switch between accounts

After creating the new organisation, it is very easy to switch between the organisations.

1
gcloud config configurations org1 

6. Extra Tip : Create alias in zshrc

If you are like me who finds the command to switch between accounts too much to remember and also type, you could create an alias in your .zshrc file so that it is easy to change.

1
alias goca='f() { gcloud config configurations activate $1 };f'

Also add another alias to list the configurations available.

1
alias gocl='gcloud config configurations list'

I choose ‘goca’ (Acronym for GOogle Configurations Activate) and ‘gocl’ (Acronym for GOogle Configurations List). You could change it to anything based on your preference.

This post is licensed under CC BY 4.0 by the author.