根据订阅标签分配 Azure 策略

问题描述 投票:0回答:1

我有一个问题,不幸的是我在 MS 文档中找不到任何明确的内容。 我们希望使用 Azure 策略通过订阅标签来确定资源等的位置。例如,我们在订阅上有一个标签:

地点 = 北欧

我们目前无法通过不同的管理组来做到这一点,因为我们只有通用的 mgm 组,例如 Spoke 等。此外,我们不想维护/继承每个资源的标签。

恐怕我已经描述了解决方案。

您有什么建议或文档吗?

azure azure-policy
1个回答
0
投票

根据订阅标签分配 Azure 策略

Azure Policy
不能直接引用订阅级标签;但是,您可以创建一个自定义
azure policy
,根据参数强制确定资源的位置。

可手动设置参数以匹配订阅标签值(北欧)。

{
  "mode": "All",
  "policyRule": {
    "if": {
      "field": "location",
      "notIn": [
        "[parameters('location')]"
      ]
    },
    "then": {
      "effect": "deny"
    }
  },
  "parameters": {
    "location": {
      "type": "String",
      "metadata": {
        "displayName": "location",
        "description": "Specify the allowed location for the resources."
      },
      "allowedValues": [
        "North Europe",
        "West Europe",
        "East US",
        "Southeast Asia"
      ],
      "defaultValue": "North Europe"
    }
  }
}

Azure 策略分配

enter image description here 如果位置与指定的策略位置不匹配,则策略会限制资源。如果它们不匹配,将会抛出错误。

enter image description here

如果位置是北欧,该策略允许创建资源。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.