【问题标题】:How to apply Azure resource locks to Resource Groups via Policy如何通过策略将 Azure 资源锁应用于资源组
【发布时间】:2019-02-26 10:41:51
【问题描述】:

我正在尝试创建一个 Azure 策略,该策略将使用“CanNotDelete”级别的资源锁部署到订阅中的资源组。

目前该策略 100% 符合,但该策略尚未创建任何锁。

我的 JSON policy.rules 文件中有以下内容;

   
{
   "if": {
      "field": "type",
      "equals": "Microsoft.Resources/resourceGroups"
   },
   "then": {
      "effect": "deployIfNotExists",
      "details": {
            "type": "Microsoft.Authorization/locks",
            "existenceCondition": {
               "field": "Microsoft.Authorization/locks/level",
               "equals": "CanNotDelete"
         },
         "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/0000-0000-0000-0000-0000000"
],
      "deployment": {
         "properties": {
            "mode": "incremental",
            "template": {
               "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
               "contentVersion": "1.0.0.0",
               "parameters": {
                  "location": {
                     "type": "string"
                  }
               },
               "resources": [
                  {
                     "type": "Microsoft.Authorization/locks",
                     "apiVersion": "2017-04-01",
                     "name": "ResourceLock",
                     "properties": {
                       "level": "CanNotDelete",
                       "notes": "Prevent accidental deletion of resource groups"
                     }
                  }
               ]
            }
         }
      }
   }
}
}  
  

【问题讨论】:

  • 您的 API 版本是否正确?所有与锁相关的文档我只能看到 2016-09-01
  • 嘿@RahulRuikar api 版本是正确的,这可以通过资源浏览器\providers 找到。

标签: azure azure-resource-group


【解决方案1】:

设法通过两项更改使其工作;

  1. if 语句路径 - Microsoft.Resources/subscriptions/resourceGroups
  2. 由于某种原因未创建托管标识,这是“deployIfNotExists”策略效果所必需的。

希望对遇到同样问题的人有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-21
    • 2020-05-07
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多