[Total: 0    Average: 0/5]

This article is written for Windows, but the same principles apply to Linux and Mac.

I need to work with multiple Google Cloud accounts and be able to easily switch my credentials between accounts. For those of you with AWS backgrounds, think profiles.

A gcloud configuration is a set of properties that govern the behavior of gcloud and other Google Cloud SDK tools. When you first install gcloud on your desktop a configuration named default is created.

A gcloud configuration is managed by gcloud config configurations. To see the list of configurations on your system:

This will output a list of configurations present on your system:

The creation of a configuration can be accomplished with gcloud or manually.

Command line Method #1:

Using the gcloud CLI, create an new configuration. This configuration will be empty. In this case I am creating a configuration named dev.

Now that we have a new configuration created, we need to activate it.

Set the account. The account is the email address that Google Cloud IAM created for you or that you authorized in Google Cloud IAM. This account is either a Google Account email address or a Google Service Account email address.

The next step is to authorize the dev configuration.

There are additional optional items that you can set in the new configuration such as default project, region and zone. Review the manual method below to see more options.

Command line Method #2

You can also use gcloud init to create a new configuration.

This will prompt you with / for the following information:

Manual Method:

For the manual method, the first step is to setup gcloud with a default account. Then go to the directory where configurations are stored and create new ones. The configurations are stored in the following directory. Replace username with your Windows user name.

For Linux:

List the contents of this directory. Each configuration starts with config_.

To create a new configuration named dev, copy config_default to config_dev.

Now using your favorite editor, modify the file. My config_default looks like this.

The important item to modify is account = user1@example.com. This user ID will be used for authentication.

The minimum configuration looks like this:

Now that we have a new configuration created, we need to activate it.

The active configuration is stored in this file.

The next step is to authorize the dev configuration.

We now have two configurations, default and dev. To switch back to the default configuration.

gcloud auth login creates the default configuration if it does not exist.

Most gcloud commands accept the command line option --configuration=CONFIGURATION_NAME. For example:

gcloud also supports the environment variable CLOUDSDK_ACTIVE_CONFIG_NAME.

To list the Google accounts that have been authorized:

This will display a list like this:

The active account is the one with the ‘*’ in the left column.

To set the project for the current configuration:

To set the region for the current configuration:

To set the zone for the current configuration:

 

Reference documentation:

Managing SDK Configurations

gcloud config configurations

gcloud auth login

gcloud auth activate-service-account

gcloud config set

Authorizing Cloud SDK Tools