Add azure resource graph action#1603
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds Azure Resource Graph query functionality to the Azure block, enabling users to execute KQL queries across multiple Azure subscriptions.
Key Changes
- Adds a new
resource_graph_queryaction that queries Azure Resource Graph using KQL - Implements subscription batching (max 1000 per query) to handle Azure API limits
- Supports both service principal and host session authentication methods
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/blocks/azure/src/lib/actions/azure-resource-graph-action.ts | Implements the new Resource Graph query action with pagination and subscription batching |
| packages/blocks/azure/src/index.ts | Registers the new action in the Azure block |
| packages/blocks/azure/test/azure-resource-graph-action.test.ts | Adds comprehensive test coverage for the new action |
| packages/blocks/azure/test/index.test.ts | Updates test to reflect the new action count |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| required: false, | ||
| validators: [Validators.minValue(1), Validators.integer], | ||
| }), | ||
| apiVersion: Property.ShortText({ |
There was a problem hiding this comment.
idk if i should have added this or not, i feel like its a pain if we have to change it in the backend everytime theres a new one
| const token = useHostSession?.['useHostSessionCheckbox'] | ||
| ? await getHostAccessToken(context.auth) | ||
| : (await authenticateUserWithAzure(context.auth)).access_token; |
There was a problem hiding this comment.
Please extract this to a new file. It will be useful for future actions.
| const batches: (string[] | undefined)[] = []; | ||
| if (subscriptionList?.length) { | ||
| for (let i = 0; i < subscriptionList.length; i += BATCH_SIZE) { | ||
| batches.push(subscriptionList.slice(i, i + BATCH_SIZE)); | ||
| } | ||
| } else { | ||
| batches.push(undefined); | ||
| } |
There was a problem hiding this comment.
Extract to a method:
function splitSubscriptionListIntoBatches(
subscriptionList?: string[],
): (string[] | undefined)[] {
if (!subscriptionList?.length) {
return [undefined];
}
const batches: string[][] = [];
for (let i = 0; i < subscriptionList.length; i += BATCH_SIZE) {
const batch = subscriptionList.slice(i, i + BATCH_SIZE);
batches.push(batch);
}
return batches;
}
| batches.push(undefined); | ||
| } | ||
|
|
||
| const allResults: Record<string, unknown>[] = []; |
There was a problem hiding this comment.
const allResults = await getQueryResults(
splitSubscriptionListIntoBatches(subscriptionList),
buildResourceGraphUrl(apiVersion),
headers,
kql,
normalizedMax,
);
|



Fixes OPS-2860