1
---
2
name: workload-manager-basics
3
metadata:
4
version: "1.0.1"
5
category: CloudObservabilityAndMonitoring
6
description: >-
7
Use this skill to manage Google Cloud Workload Manager evaluations, rules,
8
scanned resources, and validation results by using public client libraries
9
and the REST API. Use when you need to inspect workload best-practice rules,
10
create and run evaluations for Google Cloud general best practices, SAP, SQL
11
Server, or custom organizational rules, review violations, export results to
12
BigQuery, or automate Workload Manager through client libraries because no
13
service-specific public CLI or MCP server is available. Don't use for general
14
Google Compute Engine instance management, VPC configuration, or standard IAM
15
auditing.
16
---
17
18
# Workload Manager Basics
19
20
Workload Manager validates enterprise workloads against Google Cloud best
21
practices and recommendations. The public client libraries are centered on
22
evaluations: define a resource scope, choose built-in or custom rules, run an
23
evaluation, then inspect results and scanned resources.
24
25
## Attribution
26
27
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
28
MUST read [Usage Attribution](references/attribution.md). For commands executed
29
directly in the terminal (never in generated scripts, Terraform, or user code),
30
prefix `gcloud` with
31
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:workload-manager-basics)"`
32
and append `agent-skills/1.0 (skill:workload-manager-basics)` to `User-Agent` headers.
33
34
## Use This Flow
35
36
```mermaid
37
flowchart LR
38
Rules["List rules"] --> Eval["Create or update evaluation"]
39
Resources["Project, folder, or org scope"] --> Eval
40
Eval --> Run["Run evaluation"]
41
Run --> Results["Inspect evaluation results"]
42
Results --> Remediate["Remediate findings"]
43
Results --> Export["Optional BigQuery export"]
44
```
45
46
## Core API Constraints
47
48
To ensure compatibility, security, and successful integration:
49
50
* **Public Surface Only:** You MUST strictly interact with Workload Manager
51
using the official public `google-cloud-workloadmanager` client library or
52
the public REST API (`workloadmanager.googleapis.com/v1`).
53
* **No Internal or Undocumented APIs:** Do NOT attempt to use internal RPC
54
protocols, private service backends, or undocumented discovery mechanisms.
55
They are not supported for public integrations and will fail.
56
* **No Service-Specific CLI:** There is no public `gcloud workload-manager`
57
CLI command group. Use `gcloud` only for authentication, IAM role
58
assignment, and fetching raw REST tokens.
59
* **Sandbox Execution Robustness (Auth/Mock Fallbacks):** When gcloud
60
authentication or Workload Manager API calls fail in sandboxed or restricted
61
environments (e.g., due to Context Aware Access token blocks, missing API
62
enablement, or
63
mock resources returning 404/403), immediately fall back to presenting
64
example code and static findings from your references instead of entering
65
retry loops. Present the correct client library code structure or REST API
66
payload example, clearly explain the auth or resource limitation, and list
67
typical rules or mock findings statically to satisfy the request.
68
69
## Prerequisites
70
71
1. Enable the Workload Manager API:
72
73
```bash
74
gcloud services enable workloadmanager.googleapis.com --quiet
75
```
76
77
2. Authenticate locally using Application Default Credentials (ADC) before
78
using client libraries:
79
80
```bash
81
gcloud auth application-default login
82
```
83
84
3. Ensure the Workload Manager service agent has the required roles granted in
85
your project (mandatory for API/client library usage, see
86
[IAM & Security](references/iam-security.md)).
87
88
4. Grant the least-privileged role needed for the task. Start with
89
`roles/workloadmanager.viewer` for read-only access to evaluation resources
90
and use `roles/workloadmanager.evaluationAdmin` or
91
`roles/workloadmanager.admin` only when creating, updating, running, or
92
deleting evaluations.
93
94
## Quick Client Library Example
95
96
Use the Python client library for the first working automation path:
97
98
```bash
99
python3 -m pip install --upgrade google-cloud-workloadmanager
100
```
101
102
```python
103
from google.cloud import workloadmanager_v1
104
105
project_id = "PROJECT_ID"
106
location = "LOCATION"
107
parent = f"projects/{project_id}/locations/{location}"
108
109
client = workloadmanager_v1.WorkloadManagerClient()
110
111
rules = client.list_rules(
112
request=workloadmanager_v1.ListRulesRequest(
113
parent=parent,
114
evaluation_type=workloadmanager_v1.Evaluation.EvaluationType.OTHER,
115
)
116
)
117
118
for rule in rules.rules:
119
print(rule.name, rule.display_name, rule.severity)
120
```
121
122
## Reference Directory
123
124
- [Core Concepts](references/core-concepts.md): Evaluations, rules, results,
125
scanned resources, supported workload types, and API shape.
126
127
- [General Best Practices](references/general-best-practices.md): Google Cloud
128
general best-practice posture checks, `OTHER` evaluation guidance, custom
129
Rego rules, and scale/automation patterns.
130
131
- [Client Libraries](references/client-library-usage.md): Python and Go client
132
library examples for listing rules, creating evaluations, running
133
evaluations, and reading findings.
134
135
- [REST Usage](references/rest-usage.md): Direct REST examples for the public
136
Workload Manager API and operations polling.
137
138
- [Public CLI Status](references/public-cli-status.md): No documented
139
service-specific `gcloud workload-manager` command group; use `gcloud` only
140
for auth, IAM, API enablement, and REST tokens.
141
142
- [Public MCP Status](references/public-mcp-status.md): No documented public
143
Workload Manager MCP server; use client libraries or REST API instead.
144
145
- [Setup Prerequisites](references/setup-prerequisites.md): Terraform examples
146
only for adjacent prerequisites such as API enablement, IAM, BigQuery export
147
datasets, and KMS keys. This is not Workload Manager resource management.
148
149
- [IAM & Security](references/iam-security.md): Workload Manager roles,
150
least-privilege guidance, service agents, data handling, and CMEK notes.
151
152
If product behavior or API fields are not covered here, check the current
153
Workload Manager product documentation and client library reference before
154
implementing.
155
156
## Authoritative References
157
158
- [Workload Manager overview](https://docs.cloud.google.com/workload-manager/docs/overview)
159
- [Google Cloud best practices](https://docs.cloud.google.com/workload-manager/docs/reference/best-practices-general)
160
- [Workload Manager REST API](https://docs.cloud.google.com/workload-manager/docs/reference/rest)
161
- [About custom rules](https://docs.cloud.google.com/workload-manager/docs/evaluate/custom-rules/about-custom-rules)
162
- [Write custom rules using Rego](https://docs.cloud.google.com/workload-manager/docs/evaluate/custom-rules/rego-custom-rules)
163
- [Python package](https://pypi.org/project/google-cloud-workloadmanager/)
164
- [Workload Manager IAM roles](https://docs.cloud.google.com/iam/docs/roles-permissions/workloadmanager)
165
- For additional information, use the Developer Knowledge MCP server `search_documents` tool.
166
167
## Additional Context
168
169
- [Mastering cloud posture management with Workload Manager](https://discuss.google.dev/t/mastering-cloud-posture-management-security-reliability-and-finops-with-workload-manager/318258)
170