Trigger: Use when working with Google Cloud Workload Manager — setup, configuration, and best practices.
Workload Manager Basics
Workload Manager validates enterprise workloads against Google Cloud best
practices and recommendations. The public client libraries are centered on
evaluations: define a resource scope, choose built-in or custom rules, run an
evaluation, then inspect results and scanned resources.
Use This Flow
flowchart LR
Rules["List rules"] --> Eval["Create or update evaluation"]
Resources["Project, folder, or org scope"] --> Eval
Eval --> Run["Run evaluation"]
Run --> Results["Inspect evaluation results"]
Results --> Remediate["Remediate findings"]
Results --> Export["Optional BigQuery export"]
Core API Constraints
To ensure compatibility, security, and successful integration:
- Public Surface Only: You MUST strictly interact with Workload Manager
using the official public
google-cloud-workloadmanager client library or
the public REST API (workloadmanager.googleapis.com/v1).
- No Internal or Undocumented APIs: Do NOT attempt to use internal RPC
protocols, private service backends, or undocumented discovery mechanisms.
They are not supported for public integrations and will fail.
- No Service-Specific CLI: There is no public
gcloud workload-manager
CLI command group. Use gcloud only for authentication, IAM role
assignment, and fetching raw REST tokens.
- Sandbox Execution Robustness (Auth/Mock Fallbacks): When gcloud
authentication or Workload Manager API calls fail in sandboxed or restricted
environments (e.g., due to Context Aware Access token blocks, missing API
enablement, or
mock resources returning 404/403), immediately fall back to presenting
example code and static findings from your references instead of entering
retry loops. Present the correct client library code structure or REST API
payload example, clearly explain the auth or resource limitation, and list
typical rules or mock findings statically to satisfy the request.
Prerequisites
Enable the Workload Manager API:
gcloud services enable workloadmanager.googleapis.com --quiet
Authenticate locally using Application Default Credentials (ADC) before
using client libraries:
gcloud auth application-default login
Ensure the Workload Manager service agent has the required roles granted in
your project (mandatory for API/client library usage, see
IAM & Security).
Grant the least-privileged role needed for the task. Start with
roles/workloadmanager.viewer for read-only access to evaluation resources
and use roles/workloadmanager.evaluationAdmin or
roles/workloadmanager.admin only when creating, updating, running, or
deleting evaluations.
Quick Client Library Example
Use the Python client library for the first working automation path:
python3 -m pip install --upgrade google-cloud-workloadmanager
from google.cloud import workloadmanager_v1
project_id = "PROJECT_ID"
location = "LOCATION"
parent = f"projects/{project_id}/locations/{location}"
client = workloadmanager_v1.WorkloadManagerClient()
rules = client.list_rules(
request=workloadmanager_v1.ListRulesRequest(
parent=parent,
evaluation_type=workloadmanager_v1.Evaluation.EvaluationType.OTHER,
)
)
for rule in rules.rules:
print(rule.name, rule.display_name, rule.severity)
Reference Directory
Core Concepts: Evaluations, rules, results,
scanned resources, supported workload types, and API shape.
General Best Practices: Google Cloud
general best-practice posture checks, OTHER evaluation guidance, custom
Rego rules, and scale/automation patterns.
Client Libraries: Python and Go client
library examples for listing rules, creating evaluations, running
evaluations, and reading findings.
REST Usage: Direct REST examples for the public
Workload Manager API and operations polling.
Public CLI Status: No documented
service-specific gcloud workload-manager command group; use gcloud only
for auth, IAM, API enablement, and REST tokens.
Public MCP Status: No documented public
Workload Manager MCP server; use client libraries or REST API instead.
Setup Prerequisites: Terraform examples
only for adjacent prerequisites such as API enablement, IAM, BigQuery export
datasets, and KMS keys. This is not Workload Manager resource management.
IAM & Security: Workload Manager roles,
least-privilege guidance, service agents, data handling, and CMEK notes.
If product behavior or API fields are not covered here, check the current
Workload Manager product documentation and client library reference before
implementing.
Authoritative References
Additional Context
1---2name: workload-manager-basics3description: **Trigger**: Use when working with Google Cloud Workload Manager — setup, configuration, and best practices.4---56**Trigger**: Use when working with Google Cloud Workload Manager — setup, configuration, and best practices.78# Workload Manager Basics910Workload Manager validates enterprise workloads against Google Cloud best11practices and recommendations. The public client libraries are centered on12evaluations: define a resource scope, choose built-in or custom rules, run an13evaluation, then inspect results and scanned resources.1415## Use This Flow1617```mermaid18flowchart LR19 Rules["List rules"] --> Eval["Create or update evaluation"]20 Resources["Project, folder, or org scope"] --> Eval21 Eval --> Run["Run evaluation"]22 Run --> Results["Inspect evaluation results"]23 Results --> Remediate["Remediate findings"]24 Results --> Export["Optional BigQuery export"]25```2627## Core API Constraints2829To ensure compatibility, security, and successful integration:3031* **Public Surface Only:** You MUST strictly interact with Workload Manager32 using the official public `google-cloud-workloadmanager` client library or33 the public REST API (`workloadmanager.googleapis.com/v1`).34* **No Internal or Undocumented APIs:** Do NOT attempt to use internal RPC35 protocols, private service backends, or undocumented discovery mechanisms.36 They are not supported for public integrations and will fail.37* **No Service-Specific CLI:** There is no public `gcloud workload-manager`38 CLI command group. Use `gcloud` only for authentication, IAM role39 assignment, and fetching raw REST tokens.40* **Sandbox Execution Robustness (Auth/Mock Fallbacks):** When gcloud41 authentication or Workload Manager API calls fail in sandboxed or restricted42 environments (e.g., due to Context Aware Access token blocks, missing API43 enablement, or44 mock resources returning 404/403), immediately fall back to presenting45 example code and static findings from your references instead of entering46 retry loops. Present the correct client library code structure or REST API47 payload example, clearly explain the auth or resource limitation, and list48 typical rules or mock findings statically to satisfy the request.4950## Prerequisites51521. Enable the Workload Manager API:5354 ```bash55 gcloud services enable workloadmanager.googleapis.com --quiet56 ```57582. Authenticate locally using Application Default Credentials (ADC) before59 using client libraries:6061 ```bash62 gcloud auth application-default login63 ```64653. Ensure the Workload Manager service agent has the required roles granted in66 your project (mandatory for API/client library usage, see67 [IAM & Security](references/iam-security.md)).68694. Grant the least-privileged role needed for the task. Start with70 `roles/workloadmanager.viewer` for read-only access to evaluation resources71 and use `roles/workloadmanager.evaluationAdmin` or72 `roles/workloadmanager.admin` only when creating, updating, running, or73 deleting evaluations.7475## Quick Client Library Example7677Use the Python client library for the first working automation path:7879```bash80python3 -m pip install --upgrade google-cloud-workloadmanager81```8283```python84from google.cloud import workloadmanager_v18586project_id = "PROJECT_ID"87location = "LOCATION"88parent = f"projects/{project_id}/locations/{location}"8990client = workloadmanager_v1.WorkloadManagerClient()9192rules = client.list_rules(93 request=workloadmanager_v1.ListRulesRequest(94 parent=parent,95 evaluation_type=workloadmanager_v1.Evaluation.EvaluationType.OTHER,96 )97)9899for rule in rules.rules:100 print(rule.name, rule.display_name, rule.severity)101```102103## Reference Directory104105- [Core Concepts](references/core-concepts.md): Evaluations, rules, results,106 scanned resources, supported workload types, and API shape.107108- [General Best Practices](references/general-best-practices.md): Google Cloud109 general best-practice posture checks, `OTHER` evaluation guidance, custom110 Rego rules, and scale/automation patterns.111112- [Client Libraries](references/client-library-usage.md): Python and Go client113 library examples for listing rules, creating evaluations, running114 evaluations, and reading findings.115116- [REST Usage](references/rest-usage.md): Direct REST examples for the public117 Workload Manager API and operations polling.118119- [Public CLI Status](references/public-cli-status.md): No documented120 service-specific `gcloud workload-manager` command group; use `gcloud` only121 for auth, IAM, API enablement, and REST tokens.122123- [Public MCP Status](references/public-mcp-status.md): No documented public124 Workload Manager MCP server; use client libraries or REST API instead.125126- [Setup Prerequisites](references/setup-prerequisites.md): Terraform examples127 only for adjacent prerequisites such as API enablement, IAM, BigQuery export128 datasets, and KMS keys. This is not Workload Manager resource management.129130- [IAM & Security](references/iam-security.md): Workload Manager roles,131 least-privilege guidance, service agents, data handling, and CMEK notes.132133If product behavior or API fields are not covered here, check the current134Workload Manager product documentation and client library reference before135implementing.136137## Authoritative References138139- [Workload Manager overview](https://docs.cloud.google.com/workload-manager/docs/overview)140- [Google Cloud best practices](https://docs.cloud.google.com/workload-manager/docs/reference/best-practices-general)141- [Workload Manager REST API](https://docs.cloud.google.com/workload-manager/docs/reference/rest)142- [About custom rules](https://docs.cloud.google.com/workload-manager/docs/evaluate/custom-rules/about-custom-rules)143- [Write custom rules using Rego](https://docs.cloud.google.com/workload-manager/docs/evaluate/custom-rules/rego-custom-rules)144- [Python package](https://pypi.org/project/google-cloud-workloadmanager/)145- [Workload Manager IAM roles](https://docs.cloud.google.com/iam/docs/roles-permissions/workloadmanager)146- For additional information, use the Developer Knowledge MCP server `search_documents` tool.147148## Additional Context149150- [Mastering cloud posture management with Workload Manager](https://discuss.google.dev/t/mastering-cloud-posture-management-security-reliability-and-finops-with-workload-manager/318258)