azureazure-ad-graph-apiazure-policyvnet

Determine Azure Resource Policy result / effect by querying Azure Graph for state of other resources


At Microsoft Ignite 2023 MS was discussing a soon-to-be-released ability for an Azure Resource Policy definition to be allowed to invoke a Graph API query and use the results as part of the Policy evaluation.

A year later and I'm struggling to find the documentation and/or ability to do this. Specifically I need to inspect our Virtual Network Peerings to ensure they are peered to VNets within the same Tenant.

Since I don't believe the Peering resource actually includes a tenant id I suspect querying Graph would be the practical option to determine if the peers reside within the current tenant.

How do I write an Azure Resource Graph query within the definition of an Azure Resource Policy, and use the results of the query to inform the outcome of the policy?


Solution

  • Note that: Azure Policy cannot directly invoke Graph API or Resource Graph queries for tenant-level validation in its policy evaluation.

    For sample, Use Azure Resource Graph to query for your Virtual Network Peering's and retrieve necessary data about the VNets involved.

    Resources
    | where type == "Microsoft.Network/virtualNetworkPeerings"
    | project name, resourceGroup, location, properties
    

    You can use the tenantId from Microsoft Graph to compare with your current tenant.