我正在通过Powershell部署拒绝策略,并收到以下错误消息
New-AzPolicyDefinition : InvalidPolicyRule : Failed to parse policy rule: 'Could not find member 'properties' on object of type
'PolicyRuleDefinition'. Path 'properties'.'.
我使用的代码是:
1 New-AzPolicyDefinition
名称'externalDeny'
-Policy 'C:\tmp\denyoms-temp.json'
-参数'C:\ tmp \ denyoms-param.json'`
以下是策略模板。
模板文件-https://pastebin.com/embed_js/HrjUWrvf 参数-https://pastebin.com/embed_js/QxEX92jf
我想可能是标签,谢谢。
答案 0 :(得分:2)
问题出在模板上。根据此documentation,模板应采用以下格式(template.json):
{
"if": {
"allOf": [
{
"field": "tags",
"Equals": "ExternalVM"
},
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines/extensions"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/publisher",
"equals": "Microsoft.Compute"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/type",
"in": "[parameters(\'notAllowedExtensions\')]"
}
]
},
"then": {
"effect": "deny"
}
}
此外,对您的参数文件进行了较小的更改,模板根据您所应用的条件要求为“数组”类型:
{
"notAllowedExtensions": {
"type": "Array",
"metadata": {
"description": "The list of extensions that will be denied. Example: BGInfo, CustomScriptExtension, JsonAADDomainExtension, VMAccessAgent.",
"displayName": "OmsAgentForLinux"
}
}
}
使用此命令执行:
New-AzPolicyDefinition -Name 'Not allowed VM Extensions' -Description 'This policy governs which VM extensions that are explicitly denied.' -Policy 'template.json' -Parameter 'parameters.json'
希望这会有所帮助!