Last active
August 14, 2025 14:32
-
-
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.
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 | |
| # 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