json - 用于添加多个标签名称和标签值的 Azure Policy

标签 json azure tags policy

需要创建一个可添加多个标签名称和标签值的 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"
}

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

最佳答案

像这样怎么样:

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

并且您还需要 2 个附加参数。

关于json - 用于添加多个标签名称和标签值的 Azure Policy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56427380/

相关文章:

sql-server - 从服务器接收结果时发生传输级错误(连接关闭且 AUTO CLOSE false)

ios - Azure 空间 anchor 无法在 Xcode 中编译

php - 显示列表中每个帖子的标签,而不使用太多查询

mysql - 检索与标签匹配的项目,并同时检索与每个项目相关的所有标签

javascript - 在javascript中执行for循环不成功

java - 如何在 springboot API 中自定义来自@query 的响应

java - 获取 json 元素 URL netbeans

java - Facebook Graph Api Webhook feed

python - AzureBlob上传错误:The specified blob already exists

sql - 如何在 SQL 中实现 bool 标记搜索?