Help us understand the problem. What is going on with this article?

gcloudコマンドでconfigurationを切り替える

More than 1 year has passed since last update.

GCP上にプロジェクトが増えてきてプロジェクトのconfigurationを切り替えながらコマンド操作したくなったときのメモです。

$ gcloud version                                                                                                                     
Google Cloud SDK 219.0.1
bq 2.0.34
core 2018.09.28
gsutil 4.34
kubectl 2018.09.17

configurationを増やす

$ gcloud init

つぎのようにいい感じに対話形式で設定できます。

Welcome! This command will take you through the configuration of gcloud.

Settings from your current configuration [default] are:
compute:
  region: asia-northeast1
  zone: asia-northeast1-b
core:
  account: [your account]
  disable_usage_reporting: 'True'
  project: [your project]

Pick configuration to use:
 [1] Re-initialize this configuration [default] with new settings
 [2] Create a new configuration
Please enter your numeric choice:  [your choice]

Enter configuration name. Names start with a lower case letter and
contain only lower case letters a-z, digits 0-9, and hyphens '-':  [newly configured name]
Your current configuration has been set to: [newly configured name]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic (1/1 checks) passed.

Choose the account you would like to use to perform operations for
this configuration:
 [1] [your account]
 [2] Log in with a new account
Please enter your numeric choice:  1

You are logged in as: [your account].

Pick cloud project to use:
 [1] [your existing project]
 [2] Create a new project
Please enter numeric choice or text value (must exactly match list
item):  [your choice]

Your current project has been set to: [your choice].

Not setting default zone/region (this feature makes it easier to use
[gcloud compute] by setting an appropriate default value for the
--zone and --region flag).
See https://cloud.google.com/compute/docs/gcloud-compute section on how to set
default compute region and zone manually. If you would like [gcloud init] to be
able to do this for you the next time you run it, make sure the
Compute Engine API is enabled for your project on the
https://console.developers.google.com/apis page.

Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use [your account] by default
* Commands will reference project `[your project ID]` by default
Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [your choice]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic -h` to learn about advanced features of the SDK like arg files and output formatting

configurationを一覧する

$ gcloud config configurations list                                                                                                  
NAME                    IS_ACTIVE  ACCOUNT         PROJECT                      DEFAULT_ZONE       DEFAULT_REGION
default                 False      [your account]  xxxxxxxx  asia-northeast1-b  asia-northeast1
[newly configured name] True       [your account]  [your project]

現在のconfiguration(config)を確認する

$ gcloud config list
[core]
account = [your account]
disable_usage_reporting = True
project = [your project]

Your active configuration is: [newly configured name]

configurationを切り替える

$ gcloud config configurations activate [configuration name like default]
Activated [configuration name like default].
toshi0607
最近はGoとServerlessが好きです!
https://toshi0607.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした