首页 > 解决方案 > Azure Policy:标记定义资源是否可以移动/部署到特定位置

问题描述

我试图根据 Azure 策略的标记(标记名称为“测试”且标记值为“是”)来阻止资源创建/迁移到特定区域之外的其他区域。到现在为止我得到了这个,但是当我分配它时,当新资源具有特定标签时,仍然可以在其他位置创建资源。此外,Azure 告诉我 if “需要一个来源并且存在”。有什么想法有什么问题吗?

    {
  "mode": "Indexed",
  "policyRule": {
    "if": {
      "AllOf": [
        {
          "field": "tags['test']",
          "exists": "true"
        },
        {
          "value": "tags['test']",
          "equals": "yes"
        },
        {
          "field": "location",
          "notIn": [
            "France Central",
            "France South",
            "North Europe",
            "West Europe"
          ]
        }
      ]
    },
    "then": {
      "effect": "deny"
    }
  },
  "parameters": {}
}

谢谢!

标签: jsonazure

解决方案


看起来我找到了答案:

{
  "if": {
    "AllOf": [
      {
        "field": "tags['test']",
        "exists": "true"
      },
      {
        "field": "tags['test']",
        "equals": "yes"
      },
      {
        "field": "location",
        "notIn": [
          "France Central",
          "France South",
          "North Europe",
          "West Europe"
        ]
      }
    ]
  },
  "then": {
    "effect": "deny"
  }
}

基本上,“值”字必须是“字段”字。


推荐阅读