Created
October 6, 2025 14:05
-
-
Save checco/18afabfb7c8a18ebb253140f71202568 to your computer and use it in GitHub Desktop.
Configurate gcloud SDK to use a project
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/bash | |
| # usage | |
| if [ -z "${1}" ]; then | |
| echo "${0}: missing account email" | |
| echo "Try '${0} [email protected] my-project-name'" | |
| exit 1 | |
| fi | |
| if [ -z "${2}" ]; then | |
| echo "${0}: missing project name" | |
| echo "Try '${0} [email protected] my-project-name'" | |
| exit 1 | |
| fi | |
| # env | |
| account=$1 | |
| project=$2 | |
| default_zone="europe-west4-a" | |
| default_region="europe-west4" | |
| function create { | |
| gcloud config configurations create ${1} --quiet >/dev/null 2>&1 | |
| gcloud config set project ${1} --quiet >/dev/null 2>&1 | |
| gcloud config set account ${2} --quiet >/dev/null 2>&1 | |
| gcloud config set compute/zone ${3} --quiet >/dev/null 2>&1 | |
| gcloud config set compute/region ${4} --quiet >/dev/null 2>&1 | |
| gcloud config set disable_usage_reporting False --quiet >/dev/null 2>&1 | |
| gcloud config set artifacts/repository eu.gcr.io --quiet >/dev/null 2>&1 | |
| gcloud config set artifacts/location europe --quiet >/dev/null 2>&1 | |
| echo -en "created \n" | |
| } | |
| if [ ! -x "$(command -v gcloud)" ]; then | |
| echo -e "Install Google Cloud SDK first \nhttps://cloud.google.com/sdk/docs/install" | |
| exit 1 | |
| fi | |
| echo -en "Setup ${project}: \t" | |
| [ $(gcloud config configurations list | awk '{print $1}' | grep ${project}) ] && echo -en "already present \n" || create ${project} ${account} ${default_zone} ${default_region} | |
| echo "" && gcloud config configurations list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment