agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/devops/gcloud/SKILL.md

gcloud

Skill15 starsChanged 41 days agoMITView on GitHub

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.

  • Reads credentials

13 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 12 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use short-lived token generation via service account impersonation:

    line 88
  2. Very specific:

    Use server-side --filter parameters to reduce payload size when querying large fleets of resources.

    line 106
  3. Very specific:

    Use --format="value(field)" when capturing output into shell variables.

    line 107

“Common” is measured: kept by at least 6 in 10 of the 12 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  • Google Cloud Platform Automation & Scripting: Managing GCP resources, clusters, IAM roles, and deployments via gcloud.
  • GKE Cluster & Workload Management: Connecting kubectl credentials and managing GKE node pools.
  • Cloud Run & Serverless Deployment: Building and deploying serverless containers with one CLI command.
  • Filtering & Formatting GCP Assets: Extracting resource data using --filter and --format.

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:

  • Authenticate CI/CD pipelines using Workload Identity Federation instead of downloading exported JSON service account keys.
  • Use server-side --filter parameters to reduce payload size when querying large fleets of resources.
  • Use --format="value(field)" when capturing output into shell variables.
  • Manage multiple GCP accounts and projects cleanly using gcloud config configurations.

Don't:

  • Download and store long-lived service account key files (.json); they are a major source of credential leaks.
  • Deploy Cloud Run services with --allow-unauthenticated for internal-only microservices.
  • Hardcode project IDs in scripts; use gcloud config get-value project.

Troubleshooting

ErrorCauseSolution
ERROR: (gcloud) The project [x] does not exist or you do not have permissionProject ID typo or user lacks Viewer role on project.Set valid project: gcloud config set project <PROJECT_ID>.
ACCESS_TOKEN_SCOPE_INSUFFICIENTUser 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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.