我创建了用于在 Synapse Analytics Workspace 上添加专用端点的自定义策略。请参阅下面的脚本。
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Synapse/workspaces"
},
"then": {
"effect": "DeployIfNotExists",
"details": {
"type": "Microsoft.Network/privateEndpoints",
"existenceScope": "subscription",
"existenceCondition": {
"allOf": [
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"equals": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Synapse/workspaces/{synapseWorkspaceName}"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "SqlOnDemand"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"equals": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Synapse/workspaces/{synapseWorkspaceName}"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "Sql"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"equals": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Synapse/workspaces/{synapseWorkspaceName}"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "dev"
}
]
}
]
},
但上述政策不合规。见下图
我相信脚本上存在不匹配的字段,非常感谢您的帮助。预先感谢您,哎呀!
正如@Romeo 所提到的,将
allOf
替换为 anyOf
应该可以解决这里的问题。发布我们的讨论作为社区利益的答案。
策略规则中allOf运算符的功能是确保特定块下的所有给定条件都应该为真。如果满足,则只有它才会评估并触发效果触发器。而如果其中包含一个条件为 true,则 anyOf 运算符的计算结果为 true。
请参阅 MSDoc,了解如何使用示例定义解释多个策略规则。
修改后的
existenceCondition
块如下:
使用
anyOf
而不是 allOf
检查突触中是否存在任何一种专用端点配置,例如 SqlOnDemand
、Sql
或 dev
,然后策略将其评估为合规配置。
"existenceCondition": {
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"equals": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('resourceGroup'), '/providers/Microsoft.Synapse/workspaces/', parameters('synapseWorkspaceName'))]"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "SqlOnDemand"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"equals": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('resourceGroup'), '/providers/Microsoft.Synapse/workspaces/', parameters('synapseWorkspaceName'))]"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "Sql"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].privateLinkServiceId",
"equals": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('resourceGroup'), '/providers/Microsoft.Synapse/workspaces/', parameters('synapseWorkspaceName'))]"
},
{
"field": "Microsoft.Network/privateEndpoints/privateLinkServiceConnections[*].groupIds[*]",
"equals": "dev"
}
]
}
]
},
定义创建成功:
参考 MSDoc,用于探索 Azure 策略定义结构中可用的所有逻辑运算符。