filtered to running instances only since non-running instances error out - it needs to query the DB to get this info

pull/2/head
Hari Sekhon 4 years ago
parent 5d08df5c30
commit 4621d24047

@ -25,7 +25,9 @@ srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC2034,SC2154
usage_description="
Lists GCP Cloud SQL instances and their users for each SQL instance in the current GCP Project
Lists GCP Cloud SQL users for each running SQL instance in the current GCP Project
Only works on running instances since it requires querying the DB. We skip non-running instances as otherwise the GCloud SDK errors out
Can optionally specify a project id using the first argument, otherwise uses currently configured project
@ -56,13 +58,15 @@ cat <<EOF
# C l o u d S Q L U s e r s
# ============================================================================ #
# running instances only
EOF
# might need this one instead sqladmin.googleapis.com
if is_service_enabled sql-component.googleapis.com; then
while read -r instance; do
gcp_info "Cloud SQL users for instance '$instance'" gcloud sql users list --instance "$instance"
done < <(gcloud sql instances list --format='get(name)')
done < <(gcloud sql instances list --format='get(name)' --filter 'state = RUNNABLE')
else
echo "Cloud SQL API (sql-component.googleapis.com) is not enabled, skipping..."
fi

Loading…
Cancel
Save