首页 > 解决方案 > 如何在 Azure 策略中强制执行标记值模式?

问题描述

我想为资源组所需的标签强制执行标签值模式“RJGVM-###”。我设法使它成为必需,但每当我输入任何值时,它仍然通过。

{
  "mode": "All",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Resources/subscriptions/resourceGroups"
        },
        {
          "not": {
            "field": "[concat('tags[',parameters('tagName'), ']')]",
            "exists": "true"
          }
        },
        {
          "value": "[resourceGroup().tags[parameters('tagName')]]",
          "notMatch": "RJGVM-###"
        }
      ]
    },
    "then": {
      "effect": "deny"
    }
  },
  "parameters": {
    "tagName": {
      "type": "String",
      "metadata": {
        "displayName": "Tag Name",
        "description": "Name of the tag, such as 'environment'"
      }
    }
  }
}

标签: jsonazurearm-templateazure-policypolicies

解决方案


请参考以下链接中提到的此示例,以确保标签值上的匹配模式:

https://github.com/Azure/azure-policy/tree/master/samples/TextPatterns/enforce-tag-match-pattern


推荐阅读