[英]Azure Policy Deploying using Powershell
我正在通过 powershell 部署拒绝策略并收到以下错误
New-AzPolicyDefinition: InvalidPolicyRule: Failed to parse policy rule: 'Could not find member 'properties' on object of type 'PolicyRuleDefinition'. Path 'properties'.'.
我使用的代码是: 1 New-AzPolicyDefinition
-name 'externalDeny' -Policy -Policy 'C:\tmp\denyoms-temp.json'
-Parameter 'C:\tmp\denyoms-param.json' `
策略模板如下。
模板文件 - https://pastebin.com/embed_js/HrjUWrvf参数 - https://pastebin.com/embed_js/QxEX92jf
我想可能是标签,在此先感谢。
问题出在模板上。 根据此文档,模板应采用以下格式(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'
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.