Azure Resource Graph KQL查询报错:动态字段无法关联SQLVM与磁盘
解决Azure Resource Graph KQL关联磁盘与SQL虚拟机查询的错误
错误原因:KQL的join操作不支持基于dynamic类型的字段作为关联键,原查询中vmid字段是dynamic类型,必须显式转换为字符串类型才能进行join。
修改后的完整查询:
resources | where type == "microsoft.sqlvirtualmachine/sqlvirtualmachines" | project id, vmid=tostring(properties.virtualMachineResourceId), name, img=properties.sqlImageOffer, sqlImgOffered=properties.sqlImageSku, sqlLicense=properties.sqlServerLicenseType | join ( resources | where type == "microsoft.compute/disks" | project managedBy=tostring(managedBy), diskSizeGB=properties.diskSizeGB, tier=properties.tier, diskIOPSRW=properties.diskIOPSReadWrite, diskMBpsReadWrite=properties.diskMBpsReadWrite, diskState=properties.diskState ) on $left.vmid == $right.managedBy
关键修改点:
- 将SQLVM查询中的
vmid=properties.virtualMachineResourceId替换为vmid=tostring(properties.virtualMachineResourceId),把dynamic类型的虚拟机资源ID转为字符串 - 将磁盘查询中的
managedBy替换为managedBy=tostring(managedBy),确保关联字段类型与左侧一致 - 保留原查询的其余逻辑,包括字段投影和join关联条件
内容的提问来源于stack exchange,提问作者Shamsul Hassan
相关产品推荐
相关产品推荐

