DEV Community

m-yoshimo
m-yoshimo

Posted on

2 1

gcloud コマンドで複数アカウントで異なるプロジェクトを設定する

個人と会社のアカウントなど、複数のアカウントで異なるプロジェクトを設定する方法について。

gcloud config configurations でアカウントとプロジェクトを追加する

gcloud config 管理には configurations という単位でアカウントとプロジェクトをまとめて管理できる。

$ gcloud config configurations list
NAME           IS_ACTIVE  ACCOUNT                           PROJECT           DEFAULT_ZONE       DEFAULT_REGION
default        True       m-yoshimoto@company.xxx.jp        product-A         asia-northeast1-b  asia-northeast1

リスト表示すると最初に作成した configurations が [default] として表示されている。
ここに configurations を追加していく。
やることは至って簡単で下記で出来る。

$ gcloud config configurations create {configurations-name}
$ gcloud config set project {project-name}
$ gcloud config set account {email-address}

実際に追加した時のコマンド実行結果がこちら。

$ gcloud config configurations create private-study

$ gcloud config set project private-1
Updated property [core/project].

$ gcloud config set account m-yoshimo-new@gmail.com
Updated property [core/account].

$ gcloud config list
[core]
account = m-yoshimo-new@gmail.com
disable_usage_reporting = True
project = private-1

Your active configuration is: [private-study]

$ gcloud config configurations list
NAME           IS_ACTIVE  ACCOUNT                         PROJECT           DEFAULT_ZONE       DEFAULT_REGION
default        True       m-yoshimoto@company.xxx.jp      product-A         asia-northeast1-b  asia-northeast1
private-study  True       m-yoshimo-new@gmail.com         private-1

zone や region は適宜、

gcloud config set compute/zone {zone-name}

等で設定すればよい。

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more