gcloud
~/.config/gcloud配下に設定が作成される
チートシート公式
チートシートgist
/icons/hr.icon
一般
~/.config/gcloud/credentials.db, ~/.config/gcloud/credentials.db
こちらに認証情報がある。sqlite3でクエリできる
~/.config/gcloud/configurations/...に設定名でファイルに設定情報がある
https://gyazo.com/1852932802240343792ce0e5a893d6bc
~/.config/gcloud/active_configに現在有効な設定が記載
gcloud alphaとgcloud betaの違い
alpha→活発的に開発されている感じでプロダクションは無理そう
beta→ほぼ完成。プロダクションもまぁおk
/icons/hr.icon
gcloud beta interactive
インタラクティブシェル発動
https://cloud.google.com/sdk/docs/interactive-gcloud
gcloud config list
現在の設定状態
gcloud projects list
projectの情報
プロジェクト番号を調査
gcloud projects describe myproject
gcloud projects describe  |  Google Cloud CLI Documentation
設定とその変更
gcloud config configurations create scala 設定を作成
gcloud config configurations activate scala 設定をdefaultから変更
gcloud config set account hoge@gmail.com 設定値を設定していく
gcloud config set project project_id projectを設定
gcloud config set compute/region asia-northeast1
複数アカウント、複数プロジェクトの設定を入れ替える
gcloud config configurations list
gcloud config configurations activate ターゲット
サービスアカウントを認証
gcloud auth activate-service-account --key-file=sa.json
各言語でのSDKを使ったプログラムを実行する場合
gcloud auth application-default login
gcloud auth loginとgcloud auth application-default login
ssh接続の設定を./ssh/configに書いてくれる
$ gcloud compute config-ssh
gcloud compute instances list
gcloud --project <project id>
実行時にプロジェクトを指定
--verbosity=debug
でコマンドのデバックログを出してくれる
インスタンスの検索
gcloud compute instances list --zones=asia-northeast1-a
gcloud compute instances list --filter="zone:asia-northeast1-a"
ネットワークリソース関係
gcloud compute networks subnets delete サブネット名 --region asia-northeast1
https://cloud.google.com/sdk/gcloud/reference/compute/networks/subnets/delete
インスタンスを作成して外部IPを取得
$ gcloud compute instances create instancename ..... --format="value(networkInterfaces0.accessConfigs0.natIP)"
networkInterfaces[0].accessConfigs[0].natIPにはEXTERNAL_IPというエイリアスがつけられてるから以下も有効
$ gcloud compute instances create instancename ..... --format="value(EXTERNAL_IP)"