LoginSignup
1
0

More than 3 years have passed since last update.

gcloudでprojectを簡単にswitchする方法

Last updated at Posted at 2019-10-25

需要があるならちゃんとしてGolangで作ります

1.追加したいプロジェクトの箱を作成する

$ gcloud config configurations create oreno-project-dev
Created [oreno-project-dev].
Activated [oreno-project-dev].

2.プロジェクトの設定を行う

$ gcloud config set compute/region us-central1
$ gcloud config set compute/zone us-central1-a
$ gcloud config set core/account oredesu@ore.com
$ gcloud config set core/project oreno-project-dev

$ gcloud config list
[compute]
region = us-central1
zone = us-central1-a
[core]
account = oredesu@ore.com
disable_usage_reporting = False
project = oreno-project-dev

Your active configuration is: [oreno-project-dev]

3. 切り替え用スクリプトを .bashrc or .zshrc に登録する

cat <<'EOF' >> ~/.bashrc

# gcloud profile switcher
function gx () {
  if test $# -eq 0; then
    gcloud config configurations list
  else
    gcloud config configurations activate $1
  fi
}
EOF

source ~/.bashrc

4.切り替えてみる

$ gx list
NAME                IS_ACTIVE  ACCOUNT                     PROJECT             DEFAULT_ZONE       DEFAULT_REGION
oreno-project-dev  True       oredesu@ore.com  oreno-project-dev  us-central1-a      us-central1
default             False      oredesu@ore.com  oreno-project      asia-northeast1-a  asia-northeast1

$ gx default
Activated [default].

$ gx list
NAME                IS_ACTIVE  ACCOUNT                     PROJECT             DEFAULT_ZONE       DEFAULT_REGION
oreno-project-dev  False      oredesu@ore.com  oreno-project-dev  us-central1-a      us-central1
default             True       oredesu@ore.com  oreno-project      asia-northeast1-a  asia-northeast1
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0