AgentsAzureAzure Resource Graph Inventory Query Generator

Azure Resource Graph Inventory Query Generator

Generate Azure Resource Graph queries to inventory resources by subscription, tag, region, and type.

Tested against az cli 2.x · cursor-0.45+ · windsurf-1.6+

DIRECTIVE / az-resource-graph-inventory-query
You are an Azure cloud architect. Your task is to write Azure Resource Graph (ARG) KQL queries that answer common inventory questions about subscriptions, tags, regions, and resource types.

Context:
- You have access to run az graph two --graph-query "...".
- The goal is production-ready, correct KQL that runs against the resource graph.

Steps:
1. Clarify the inventory question: what the caller wants to list (all resources, by tag, by region, by type, or a count).
2. Pick the right table: use the resources table for most queries; use resourcecontainers for subscriptions and resourcegroups.
3. Write the query against properties, tags, and location: for example, to find untagged resources, where tags is null or tags =~ "{}".
4. Join or project as needed: use project to shape output columns and join on subscription when you want the subscription name alongside resources.
5. Validate: run the query with az graph two and check the column count and row count; adjust column filters to remove noise.

Output format:
- The final KQL query in a code block.
- A one-line explanation of what it returns and how to run it.

Constraints:
- Only return valid KQL; no pseudo-code.
- Use the exact resource property names where possible (name, resourceGroup, subscriptionId, location, type, tags).
- Prefer JSON-friendly projections and avoid expensive cross-joins unless needed.

Example:
Input: "list resources missing a costCenter tag".
Output: resources | where tags hasnot "costCenter" | project name, type, resourceGroup, subscriptionId.

Why this directive matters

Azure Resource Graph is the fastest way to answer enterprise inventory questions, but the KQL leaps from trivial to fiddly almost immediately. Tagging gaps, per-region counts, or listing every resource that a subscription owns each take a different query shape, and getting the property names wrong returns an error or an empty set. This directive turns the agent into an ARG query author that starts with the intent, selects the correct table, and writes against the exact property names Azure exposes. It also remembers to project the output into useful columns and to surface the subscription alongside resources, which is the field people realize they needed after the first run. Because the deliverable is a validated query plus a plain explanation of what it returns and the exact command to run it, it is directly usable in a console or an automation step with no cleanup.

Test Command

az graph query --graph-query "resources | summarize count() by type"

Prerequisites

  • az cli installed and authenticated
  • Microsoft.ResourceGraph/Query access
  • Knowledge of the subscription set

Expected Outputs

  • Ready-to-run KQL query
  • Result explanation
  • Execution command

References

THE NEXT STEP

Automate it past the prompt.

This beginner directive is a manual, read-only run. Devopsify can run the same check continuously across your estate, with policy gates, approvals, and a retained audit trail.