首页 > 解决方案 > 设置 Azure 位置策略限制

问题描述

我想定义一个 Azure 策略,其中只能在订阅级别对“美国西部”和美国东部进行部署。

我知道我正在尝试填充一系列位置,但我在某些地方出错了;

{
  "policyRule": {
    "if": {
      "not": {
        "field": "location",
        "in": "[parameters('allowedLocations')]"
      }
    },
    "then": {
      "effect": "deny"
    }
  },
  "parameters": {
    "allowedLocations": {
      "type": "Array",
      "metadata": {
        "description": "The list of allowed locations for resources.",
        "displayName": "Allowed locations",
        "strongType": "location",
        "value": [ "West US", "East US" ], 
      }
    }
  }
}

标签: arraysjsonazureazure-resource-managerazure-policy

解决方案


Azure 策略具有定义和分配的概念。您提供的 JSON 符合定义的格式。

要使策略生效,您需要将定义分配给您希望策略应用的订阅。

在此处输入图像描述

您尝试应用的策略也可作为内置定义使用。您可以使用 Azure 门户直接分配此定义。

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyMenuBlade/Definitions


推荐阅读