【问题标题】:Azure Policy to add multiple tag names and tag valuesAzure Policy 添加多个标记名称和标记值
【发布时间】:2019-10-19 00:14:06
【问题描述】:

需要创建一个可以添加多个标记名称和标记值的 Azure 策略

需要在 Azure 中分配一个策略,其中资源将仅使用指定的标记名称和值进行部署。

{
   "properties": {
      "displayName": "Enforce tag and its value",
      "policyType": "BuiltIn",
      "description": "Enforces a required tag and its value.",
      "parameters": {
         "tagName": {
            "type": "String",
            "metadata": {
               "description": "Name of the tag, such as costCenter"
            }
         },
         "tagValue": {
            "type": "String",
            "metadata": {
               "description": "Value of the tag, such as headquarter"
            }
         }
      },
      "policyRule": {
         "if": {
            "not": {
               "field": "[concat('tags[', parameters('tagName'), ']')]",
               "equals": "[parameters('tagValue')]"
            }
         },
         "then": {
            "effect": "deny"
         }
      }
   },
   "id": "/providers/Microsoft.Authorization/policyDefinitions/1e30110a-5ceb-460c-a204-c1c3969c6d62",
   "type": "Microsoft.Authorization/policyDefinitions",
   "name": "1e30110a-5ceb-460c-a204-c1c3969c6d62"
}

代码描述了如何为单个标签添加标签名称和值。 需要添加多个标签值和标签名称。

【问题讨论】:

    标签: json azure tags policy


    【解决方案1】:

    这样的事情怎么样:

    "if": {
        "not": {
            "allOf": [
                {
                    "field": "[concat('tags[', parameters('tagName1'), ']')]",
                    "equals": "[parameters('tagValue1')]"
                },
                {
                    "field": "[concat('tags[', parameters('tagName2'), ']')]",
                    "equals": "[parameters('tagValue2')]"
                }
            ]
        },
        "then": {
           "effect": "deny"
        }
    },
    

    您还需要 2 个附加参数。

    【讨论】:

    • 如果我们需要添加一个标签名称,根据场景可以有多个标签值怎么办?例如,Tag Name:Environment Tag Value:Prod、Non-Prod、UAT、Test 所以,这里的 Tag Name 对所有的值都是一样的,不同的场景值会相应地改变。相同的代码可能是什么?
    • 这将是一个新问题,如果这回答了您的问题,请接受它并开始一个新问题。我很乐意调查那个。
    • 是的,它确实回答了我的问题。谢谢。您能否查看下面的链接以及稍后讨​​论的类似问题? stackoverflow.com/questions/56629219/…
    猜你喜欢
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 2022-01-10
    • 2015-09-15
    • 1970-01-01
    • 2013-11-19
    相关资源
    最近更新 更多