【问题标题】:Azure ARM policy deployment deny specific sku.nameAzure ARM 策略部署拒绝特定 sku.name
【发布时间】:2021-09-12 19:26:19
【问题描述】:

我对策略的arm部署非常困惑,希望有人可以帮助我解决这个问题。

我想制定一项政策,根据他们的 Sku.name 拒绝数据库部署。

是的,我想允许创建它们是 standardBasic 的数据库,并拒绝所有其他 sku。

我有这个json 配置,但它只能部分工作。

{
    "properties": {
      "displayName": "Not allowed resource types",
      "policyType": "BuiltIn",
      "mode": "All",
      "description": "This policy enables you to specify the resource types that your organization cannot deploy.",
      "parameters": {
        "listOfAllowedSKUs": {
          "type": "Array",
          "metadata": {
            "description": "The list of resource types that cannot be deployed.",
            "displayName": "Not allowed resource types",
            "strongType": "resourceTypes"
          }
        }
      },
      "policyRule": {
        "if": {
          "field": "type",
          "in": "[parameters('listOfAllowedSKUs')]"
        },
        "then": {
          "effect": "Deny"
        }
      }
    },
    "id": "/providers/Microsoft.Authorization/policyDefinitions/6c112d4e-5bc7-47ae-a041-ea2d9dccd749",
    "type": "Microsoft.Authorization/policyDefinitions",
    "name": "6c112d4e-5bc7-47ae-a041-ea2d9dccd749"
  }

参数:

{
    "listOfAllowedSKUs": {
    "type": "Array",
    "allowedValues": [
      "Standard",
      "Basic"
    ],
    "metadata": {
      "displayName": "Allowed SKUs",
      "description": "The list of SKUs that can be specified for databases."
    }
  }
}

和规则:

{
    "if": {
        "not": {
          "field": "Microsoft.Sql/servers/databases/sku.name",
            "in": "[parameters('listOfAllowedSKUs')]"
          }
    },
    "then": {
      "effect": "deny"
    }
}

当我部署此策略时,我只能部署基本 Sku,而所有其他(包括标准)都被拒绝。

如何允许同时创建 BasicStandard

非常感谢愿意花费宝贵时间帮助我理解这一点的人。

【问题讨论】:

  • 您需要过滤sku.tier。对于 basic,name 和 tier 是相同的,但是对于 standard,tier = standard 并且 name 可以是 S1、S2 等......
  • 是的,我只是设法使用Microsoft.Sql/servers/databases/sku.tier 使它工作,我只能创建标准和基本。如果您想将其发布为答案,我将投票。只是一个基本问题,我在哪里可以找到资源的所有规范,例如Microsoft.Sql/servers/databases/sku.tier 等?是否有我可以阅读的文档来了解我可以定位哪些子资源?

标签: azure azure-sql-database azure-resource-manager azure-policy azure-bicep


【解决方案1】:

看着documentation

  • sku 层:特定 SKU 的层或版本,例如基本版、高级版。
  • sku 名称:SKU 的名称,通常为字母 + 数字代码,例如P3。

因此,在您的情况下,您需要过滤 sku 层。 对于 Basic,name 和 tier 相同。
对于标准,层级是标准,但名称可以是 S1...S12

{
    "if": {
        "not": {
          "field": "Microsoft.Sql/servers/databases/sku.tier",
            "in": "[parameters('listOfAllowedSKUs')]"
          }
    },
    "then": {
      "effect": "deny"
    }
}

【讨论】:

    猜你喜欢
    • 2021-11-05
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    相关资源
    最近更新 更多