Lists every project under a GCP organization and enables the Service Usage API
(serviceusage.googleapis.com) on each one.
Runs in dry-run mode by default — it only lists the projects and prints what
it would do. Pass --dry-run false to actually enable the service.
To run the script, you must have:
- Google Cloud CLI (
gcloud) - jq
- An authenticated gcloud session:
gcloud auth login - IAM permission to list projects under the organization and to enable services
on each project (
roles/serviceusage.serviceUsageAdminor equivalent, plusroles/browser/resourcemanager.projects.listat the org level).
-
Ensure that you have execute privileges:
chmod +x enable-serviceusage.sh
-
Authenticate and run:
gcloud auth login ./enable-serviceusage.sh --org-id 123456789012
./enable-serviceusage.sh --org-id <ORG_ID> [options]--org-id (Required)
[String] The numeric GCP organization ID whose projects will be processed.
--service (Optional)
[String] Comma-separated list of one or more services to enable. Defaults to
serviceusage.googleapis.com. Example:serviceusage.googleapis.com,orgpolicy.googleapis.com.
--dry-run (Optional)
[String] When
falsethe service is enabled on each project; whentruethe script only lists the projects and what it would do. Defaults totrue.
--skip-system (Optional)
[String] When
trueprojects whose lifecycle state is notACTIVE(e.g.DELETE_REQUESTED) are skipped. Defaults totrue.
--help
Lists all the options and their usages.
./enable-serviceusage.sh --org-id 123456789012./enable-serviceusage.sh --org-id 123456789012 --dry-run false./enable-serviceusage.sh --org-id 123456789012 --service compute.googleapis.com --dry-run false./enable-serviceusage.sh --org-id 123456789012 \
--service serviceusage.googleapis.com,orgpolicy.googleapis.com --dry-run false- The script discovers projects at any depth in the org. It walks the
organization's folder tree (folders only, via
gcloud resource-manager folders list) to build the full set of parent containers, then filters the project list locally by parent id. This covers folder-nested projects that a plainparent.id=<org>filter would miss, and avoids the Cloud Asset API (which requires a usable quota project). - It only sees projects the authenticated account has permission to list. Projects in the org that the caller cannot access are silently absent.
- Enabling a service is idempotent — re-running on a project that already has the API enabled is a no-op.