Last active
August 29, 2015 14:22
-
-
Save holysugar/391b359c2f531b4fc506 to your computer and use it in GitHub Desktop.
GCEでメタデータからインスタンス名を引く
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # ここでは environment と role というメタデータがあると仮定 | |
| environment=$1 | |
| role=$2 | |
| if [ -z "$role" ]; then | |
| echo "[usage] $0 environment role" | |
| exit 1 | |
| fi | |
| gcloud compute instances list --format json | | |
| jq -r "map(select(.metadata.items)) | | |
| map(select(.metadata.items | from_entries | .environment == \"${environment}\" and .role == \"${role}\")) | | |
| .[].name" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment