A team built zombie-sweep to hunt unused Google Cloud resources that still bill without doing any work. The project lives at https://github.com/xbill9/zombie-sweep-gcp and strings together Cloud Scheduler, Workflows, Cloud Run and AlloyDB Express into a daily pipeline. The goal: produce a waste report without adding a database bill to monitor.

Why AlloyDB Express makes the promise possible

AlloyDB Express is a preview configuration of AlloyDB for PostgreSQL built for prototypes and small workloads. Three properties from its documentation determine the bill. First, it scales to zero: when an instance is idle, it scales down to zero compute so you aren't billed for compute during periods of inactivity. The idle threshold sits at 15 minutes, and the instance wakes in approximately 20 seconds. Second, storage stops at 20 GB; once that limit is reached, further write operations aren't allowed. Storage bills for what is used, not for what is provisioned. Third, compute comes in two sizes: 1 vCPU with 4 GB RAM, or 2 vCPUs with 8 GB RAM, billed per second as 1 or 2 compute units.

A database that cannot grow past 2 compute units or 20 GB has a calculable worst case. Priced from the Cloud Billing Catalog API for us-west1, with the instance never idle and storage full, the monthly ceiling works out to $89.95 for a 1 vCPU instance and $173.90 for 2 vCPU. The daily sweep keeps the instance awake for minutes a day, and the free tier covers that: each month includes 50 compute units and 2 GB of storage per billing account for the first 12 months.

What counts as a zombie resource

A zombie resource still bills and no longer does any work. Examples: a stopped VM whose disks still cost money, a snapshot of a disk that was deleted, a static IP attached to nothing, a secret nobody has updated in months. They collect in projects used for one experiment, in zones tried once, and behind instances that were stopped and forgotten instead of deleted.

Google Cloud already offers some of this detection through Recommender, which has idle-resource recommenders for VMs, persistent disks, IP addresses, custom images, Cloud SQL instances and GKE clusters. This sweep queries 7 of those recommenders. Additionally, zombiescan-gcp is an open-source scanner with 20 checks, covering orphaned snapshots, stale Artifact Registry repositories, stale secrets, Cloud NAT gateways serving nothing, Filestore instances nothing can mount, unused firewall rules and subnets, Cloud DNS zones and uptime checks for deleted resources. Zombie Sweep runs both sources in every cycle and compares them resource by resource, so the report shows which source found what.

What you need before deploying

At this point you should have: a Google Cloud project with billing enabled, the Google Cloud CLI with the beta component for AlloyDB Express, git and python3 on the deploying machine, and the Recommender, Cloud Run, Workflows, Cloud Scheduler, AlloyDB, Secret Manager, Vertex AI and IAP APIs enabled.

How the pieces fit together

Cloud Scheduler triggers zombie-sweep-daily at 06:00 UTC. Workflows zombie-sweep runs two Cloud Run jobs in parallel — one in MODE=zombiescan, one in MODE=recommender — then posts the run id to an ADK agent's /briefing route and runs a third job with MODE=finish to store the briefing. One AlloyDB Express instance holds two tables and two views. One Cloud Run service holds the agent and its SQL tools.

Creating the AlloyDB Express cluster

Create the cluster and primary instance with gcloud beta commands, setting a password and enabling public DNS. us-west1 is the only US region Express supports. The instance reports PostgreSQL 18.4 and max_connections 200, both fixed by Express. Then enable IAM database authentication with one flag update.

Two tables and two views

The runs table holds one row per sweep, keyed by the Workflows execution id, with the agent's briefing. The findings table holds one row per resource per source, with columns for run_id, source, project, check_id, resource and monthly_cost. The two sources name the same resource differently: zombiescan stores w1; Recommender stores //compute.googleapis.com/projects/p/regions/us-central1/addresses/w1. A view called findings_keyed reduces both to (project, kind, name). Another view, findings_compared, adds a found_by_both field that checks whether the same project-kind-name appears under both sources.

One Cloud Run job, three modes

sweep/job.py runs one source against one project and prints one JSON line. MODE=zombiescan runs zombiescan-gcp's 20 checks and prices each finding from the public price list. MODE=recommender reads the 7 idle-resource recommenders at every zone, region or global location each one uses. MODE=finish stores the briefing and marks the run DONE. Each source mode deletes and re-inserts its own rows for the run, so a retried job leaves no duplicates. In Cloud Run the job logs into AlloyDB with IAM database authentication as its service account: no password in the job, and a zombie_writer role that can write findings and close runs.

Workflows runs both sources, then asks for a briefing

The two sources run as parallel branches, each one a Cloud Run job execution through the Workflows connector. Then the workflow posts the run id to the agent's /briefing route and runs the job a third time with MODE=finish to store what came back. A failed briefing does not fail the sweep; the run closes without one.

Behind IAP, Workflows signs its own JWT. The agent's Cloud Run service sits behind Identity-Aware Proxy, so a person opens the report page with a Google sign-in. IAP with the Google-managed OAuth client accepts a JWT signed by a service account with aud set to the URL, so the workflow signs one as itself and sends it as a bearer token. The workflow's service account holds Service Account Token Creator on itself only, and roles/iap.httpsResourceAccessor on the agent. Workflows expressions take no map literals, so the claims are built in an assign step first.

The agent: ADK with MCP Toolbox as a sidecar

The agent is a FastAPI app running an ADK LlmAgent on Gemini through Vertex AI. Its only access to the data is MCP Toolbox for Databases, running as a second container in the same Cloud Run service on 127.0.0.1:5000. Toolbox connects to AlloyDB with IAM login as the agent's service account, which holds a read-only role.

Toolbox exposes 8 SQL tools: list_runs, totals, top_waste, count_findings, only_one_source, diff_vs_previous, finding_history and run_briefing. The tool definitions live in Secret Manager and are mounted into the Toolbox container as a file. The agent serves four routes: GET / for the report page, POST /ask for questions, POST /briefing for the workflow, and GET /health, because Cloud Run reserves /healthz.

Every number comes from SQL

The agent is told never to add, count, average or compare numbers itself. Every count and sum is a SQL tool, and count_findings takes filters and returns the exact answer. The tool returns exact count, total, minimum and maximum monthly cost of the findings in one run that match every filter given. min_monthly_cost is inclusive (>=). The briefing is then checked figure by figure against SQL run directly on the database, with no model involved.

A read-only hint matters: the Toolbox source is declared readOnly: true. With that set, Toolbox keeps a postgres-sql tool only when the tool declares annotations: {readOnlyHint: true}. All 8 tools here carry it. A new tool without it does not appear in the agent's tool list.

Deploy with one script

python3 sql/apply.py applies the schema and views from a workstation through the AlloyDB Python connector. deploy/deploy.sh sets up service accounts, IAM, job, agent, IAP, workflow and schedule. It is idempotent and safe to run again; it keeps only the newest version of the Toolbox secret enabled and sets an Artifact Registry cleanup policy that keeps the newest 3 images. python3 sql/apply.py grants.sql assigns database roles for the IAM users deploy.sh created. deploy/deploy.sh run performs one sweep now.

The schedule is 0 6 * * * in UTC. Across 11 successful sweeps, each took 54 to 127 seconds end to end.

What the sweep found

Run 854715f3, 2026-11-20, one project showed 27 zombiescan findings costing $128.86 a month and 1 recommender finding at $7.30. One resource was found by both: a static IP address w1 at $7.30 a month. Everything else came from zombiescan alone.

  • stopped-instance: 5 findings at $65.28
  • orphaned-snapshot: 5 findings at $53.19
  • stale-artifact-repository: 4 findings at $2.55
  • stale-secret: 8 findings at $0.54
  • unmanaged-gcs-bucket: 2 findings at $0.00
  • unused-firewall-rule: 2 findings at $0.00

The agent's briefing stated totals by source, top waste items (snapshot-w5-opt at 53.19, windows at 23.94, debian13b at 13.06, w1 at 10.88, w2 at 10.88) and a diff vs previous run fe2aac43-c1a1-49d4-8645-1afbd80ff204: 28 findings costing 136.16 are unchanged. Every figure in it matches the SQL computed for the same run.

What it costs

Docs/cost.py prices the sweep from the Cloud Billing Catalog API and measures usage from the project: 37 Cloud Run job executions averaging 24.4 seconds, 7 briefings averaging 31.6 seconds, and the database at 17880855 bytes. For 30 daily sweeps the table breaks down like this:

  • AlloyDB Express compute, 7.95 to 8.56 CU-hours: $0.91 to $0.98 list price, $0.00 with the Express free tier
  • AlloyDB Express storage: $0.0050 list price, $0.00 with the Express free tier
  • Cloud Run job, 3 executions a sweep: $0.0439
  • Cloud Run agent, 1 briefing a sweep: $0.0491
  • Total, upper end: $1.08 list price, $0.09 with the Express free tier

AlloyDB compute hours are each sweep's duration plus the 15-minute idle period before the instance pauses. The 50 free compute units leave 41.44 a month after the sweeps: room for about 166 more wake-ups from people opening the report page or asking the agent a question. The database line stays at $0.00 for as long as the free tier lasts, and after that it has the ceiling worked out above: $89.95 a month for this 1 vCPU instance if it never sleeps at all.

AlloyDB Express versus full AlloyDB

A comparison from the AlloyDB Express documentation's own table highlights the differences:

  • Compute when idle: Express scales to zero; full AlloyDB is always provisioned
  • Pricing: Express is usage-based with a monthly free tier; full AlloyDB is provisioned hourly with a 30-day trial
  • Largest bill possible: Express is bounded at 2 vCPU, 20 GB; full AlloyDB grows with the cluster
  • Compute: Express offers 1 or 2 vCPU, one zonal instance; full AlloyDB goes up to 288 vCPUs with read pools
  • Storage: Express caps at 20 GB; full AlloyDB goes up to 128 TB
  • Backups, PITR, HA: None in Express; yes with 99.99% regional SLA for full AlloyDB
  • PostgreSQL versions: 18 in Express; 14 to 18 in full AlloyDB
  • Terraform: Not supported in Express; yes in full AlloyDB

Use AlloyDB Express for a scheduled job that writes a few megabytes a day and is read now and then. It sleeps between sweeps, its storage cannot grow past 20 GB, and its largest possible bill is a number you can compute before you create it. Move to full AlloyDB when the data needs backups, high availability or an SLA. The upgrade is in place and keeps the connection string; there is no way back to Express afterwards.

Summary

The goal of this article was to run a daily sweep for unused Google Cloud resources without adding a database bill to watch. The key to the solution was AlloyDB Express, which scales to zero between sweeps, caps its own storage, and fits this workload within a predictable cost ceiling.