Gcloud

From G1Joshi/Agent-Skills · View interactive version

Gcloud is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Google Cloud CLI (gcloud) assistance covering configurations, service accounts, IAM impersonation, and Cloud SDK scripting. Use when automating GCP resources and deploying Google Cloud services.

How to use this skill

Skill file

Google Cloud CLI (`gcloud`)

The gcloud CLI is part of the Google Cloud SDK. It manages authentication, local configuration, and developer workflows for GCP.

When to Use

Quick Start

# Initialize
gcloud init

# Authenticate for local code (ADC)
gcloud auth application-default login

# Deploy to Cloud Run
gcloud run deploy my-service --source .

Core Concepts

Advanced Filtering and Formatting with --filter & --format

Extracting precise JSON/table projections from GCP:

# List all running GCE instances with name, zone, and internal IP
gcloud compute instances list \
  --filter="status=RUNNING AND zone:us-central1" \
  --format="table(name,zone,networkInterfaces[0].networkIP:label=INTERNAL_IP)"

# Export single property as unquoted string
PROJECT_NUMBER=$(gcloud projects describe my-prod-project \
  --format="value(projectNumber)")

One-Command Serverless Deployment with Cloud Run

Building from source and deploying containerized apps:

# Build and deploy directly to Cloud Run
gcloud run deploy customer-api \
  --source . \
  --region us-central1 \
  --platform managed \
  --allow-unauthenticated \
  --min-instances 1 \
  --max-instances 20 \
  --memory 1Gi \
  --cpu 1 \
  --set-env-vars "NODE_ENV=production"

Workload Identity Federation for CI/CD

Configuring GitHub Actions or GitLab to authenticate without JSON service account keys:

# Create Workload Identity Pool
gcloud iam workload-identity-pools create "github-pool" \
  --location="global" \
  --description="Pool for GitHub Actions"

# Authorize GitHub repository to impersonate service account
gcloud iam service-accounts add-iam-policy-binding "deployer-sa@my-prod.iam.gserviceaccount.com" \
  --role="roles/iam.workloadIdentityUser" \
  --member="principalSet://iam.googleapis.com/projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/github-pool/attribute.repository/my-org/my-repo"

Common Patterns

Service Account Impersonation Without Exporting JSON Keys

Problem: Exporting static service account JSON keys creates credential leak risks.

Solution:

Use short-lived token generation via service account impersonation:

# Impersonate deployer service account dynamically
gcloud config set auth/impersonate_service_account deployer@my-project.iam.gserviceaccount.com

# Deploy Cloud Run service using impersonated credentials
gcloud run deploy api-service \
  --image gcr.io/my-project/api:latest \
  --region us-central1 \
  --platform managed

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :----------------------------------------------------------------------------- | :----------------------------------------------------- | :---------------------------------------------------------------- |

| ERROR: (gcloud) The project [x] does not exist or you do not have permission | Project ID typo or user lacks Viewer role on project. | Set valid project: gcloud config set project <PROJECT_ID>. |

| ACCESS_TOKEN_SCOPE_INSUFFICIENT | User authenticated with limited OAuth scopes. | Re-authenticate: gcloud auth login --enable-gdrive-access. |

| Quota exceeded for metric ... | Target region reached GCP quota limit for compute/IPs. | Request quota increase in GCP Console under IAM & Admin > Quotas. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.