Skip to content

Instantly share code, notes, and snippets.

@jjtroberts
Created September 17, 2025 21:40
Show Gist options
  • Select an option

  • Save jjtroberts/436167acf5d776d01c8aeb4ba3d17f65 to your computer and use it in GitHub Desktop.

Select an option

Save jjtroberts/436167acf5d776d01c8aeb4ba3d17f65 to your computer and use it in GitHub Desktop.
# Color vars
RED=$'\033[31m'
GREEN=$'\033[32m'
RESET=$'\033[0m'
# Check if a GCP service account exists
# Usage: is_sa <service_account_email> <project_id>
# Example: is_sa my-foobar-sa my-foobar-dev-project
function is_sa() {
local service_account_email=$1
local project_id=$2
if gcloud iam service-accounts describe "${service_account_email}@${project_id}.iam.gserviceaccount.com" --project "$project_id" &>/dev/null; then
echo "${GREEN}Service account ${service_account_email} exists in project ${project_id}.${RESET}"
return 0
else
echo "${RED}Service account ${service_account_email} does not exist in project ${project_id}.${RESET}"
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment