Skip to content

Instantly share code, notes, and snippets.

@obar1
Last active August 14, 2025 14:32
Show Gist options
  • Select an option

  • Save obar1/81b0910253d9bc04e566c9939c18c2d0 to your computer and use it in GitHub Desktop.

Select an option

Save obar1/81b0910253d9bc04e566c9939c18c2d0 to your computer and use it in GitHub Desktop.
This Bash script is used to authenticate and configure access to a Google Cloud Platform (GCP) project using the gcloud CLI. It ensures the user provides a project ID, sets it as an environment variable, and then runs a series of GCP authentication and configuration commands.
#!/bin/bash
# Check if a project ID was provided
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo "Usage: $(basename "$0") <gcp_project_id>"
echo "This script authenticates and configures gcloud for the specified GCP project."
exit 0
fi
# Export the project ID
export gcp_dev_project_id="$1"
echo "Using project ID: $gcp_dev_project_id :)"
read -p "Press Enter to continue..."
# Run GCP authentication and configuration commands
gcloud auth login --no-launch-browser || { echo "User login failed"; exit 1; }
gcloud auth application-default login --no-launch-browser || { echo "ADC login failed"; exit 1; }
gcloud config set project "$gcp_dev_project_id" || { echo "Failed to set project"; exit 1; }
gcloud auth application-default set-quota-project "$gcp_dev_project_id" || { echo "Failed to set quota project"; exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment