Skip to content

Instantly share code, notes, and snippets.

@FGtatsuro
Last active July 31, 2019 15:15
Show Gist options
  • Save FGtatsuro/7ae5964953d70a42a7be291cdb54b4b6 to your computer and use it in GitHub Desktop.
Save FGtatsuro/7ae5964953d70a42a7be291cdb54b4b6 to your computer and use it in GitHub Desktop.
Google Cloud SDK utility
# リソースタイプ
$ gcloud deployment-manager types list | awk 'NR>=2' | grep -E -v 'beta|alpha' | sort -u
$ gcloud deployment-manager types list | tail -n +2 | grep -E -v 'beta|alpha' | sort -u
$ gcloud deployment-manager types list --filter='name !~ alpha|beta'| tail -n +2 | sort -u
$ gcloud deployment-manager types list --filter='name:compute AND NAME !~ alpha|beta' | tail -n +2 | sort -u
# マシンタイプ
# NOTE: --sort-byオプションがCPUS,MEMORY_GBに対して上手く効かない
$ gcloud compute machine-types list --filter='zone:asia-northeast1-a' | sort -n -k 3,3 # CPU数順
$ gcloud compute machine-types list --filter='zone:asia-northeast1-a' | sort -n -k 4,4 # メモリ順
# イメージ
$ gcloud compute images list --filter='name:ubuntu'
# gcloud 設定
## 設定確認
$ gcloud config configurations list
## 設定切り替え
$ gcloud config configurations activate <config名>
# インスタンス
gcloud compute instances list
# SSH
## gcloud経由
## 初回はSSH鍵の生成が入る
$ gcloud compute ssh devenv
## SSHクライアント経由
## エイリアスを~/.ssh/configに追加
$ gcloud compute config-ssh
$ ssh devenv.<zone>.<projectid>
# Deployment Managerのリソースタイプのスキーマを表示する
$ PROVIDER=`gcloud beta deployment-manager type-providers list --project gcp-types | tail -n +2 | peco`; \
TYPE=`gcloud beta deployment-manager types list --filter="provider:$PROVIDER" | grep '\- ' | sed 's/- //g' | peco`; \
gcloud beta deployment-manager types describe --provider $PROVIDER $TYPE --project gcp-types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment