対象読者
複数のプロジェクトを扱う人
権限*があるすべてのアクティブなプロジェクトを一覧表示
gcloud projects list
指定できるパラメータは レファレンス参照
*アクティブなアカウントに所有者、編集者、ブラウザー、または閲覧者の権限
現在アクティブな設定(Configuration)のプロパティを一覧で表示
gcloud config list
結果
- 以下の例はアクティブな設定(Configuration)はdefaultという意味
[accessibility]
screen_reader = True
[core]
account = YourAccount@email.com
disable_usage_reporting = True
project = your-project-id
Your active configuration is: [default]
新規で設定(Configuration)のNAME({設定名})を作成
gcloud config configurations create {任意の設定名}
結果
Created [{任意の設定名}].
Activated [{任意の設定名}].
- 設定が作成され、アクティブな設定が上記で作った設定に変更される
確認
先ほどのgcloud config list
を打つとactive configurationが下記のようになる
Your active configuration is: [{任意の設定名}]
- アクティブな設定(Configuration)が今作成した設定に変更されたという意味
新規で作成した設定(Configuration)に各項目を紐づけ
PROJECTを設定
gcloud config set project {PROJECTのID}
ACCOUNTを設定
gcloud config set account {GCPのemailアドレス}
ZONE,REGIONはデフォルトでも入っていなかったので要らないかもしれない・・・
ZONEを設定
gcloud config set compute/region {ZONE}
REGIONを設定
gcloud config set compute/region {REGION}
- zoneやregionはAPIが有効でない場合、以下のように聞かれるので有効にする場合はyを入力
API [compute.googleapis.com] not enabled on project [your-project-id]. Would you like to enable and retry (this will
take a few minutes)? (y/N)?
上記で設定した値を解除する
gcloud config unset {PROJECTのID,GCPのemailアドレス,ZONE,REGION}
設定した値を確認
- osによって若干表示が違うかもです
gcloud config configurations list
// 結果
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default False YourAccount@email.com your-project-ID
任意の設定名 True YourAccount@email.com new-project-ID ZONE REGION
アクティブな設定を切り替える
gcloud config configurations activate {設定名}
例
// アクティブな設定をdefaultに切り替える
gcloud config configurations activate default
// アクティブな設定を新規作成した設定に切り替える
gcloud config configurations activate {自分が上で作成した設定名}
設定の削除
- activeだと削除できないので他の設定に切り替えて行う
gcloud config configurations delete {設定名}
結果
The following configurations will be deleted:
- {設定名}
Do you want to continue (Y/n)? Y
Deleted [{設定名}].