Azure Policy パターン: field プロパティ

field 演算子は、指定したプロパティまたは別名を、与えられた条件に合うように、指定した値に評価します。

ポリシー定義の例

このポリシー定義を使用すると、組織の地理的な場所の要件を満たすことができるリージョンを定義できます。 許容されるリソースは、パラメーター listOfAllowedLocations ("配列") で定義されます。 定義に一致するリソースは、拒否されます。

{
    "properties": {
        "displayName": "Allowed locations",
        "policyType": "BuiltIn",
        "description": "This policy enables you to restrict the locations your organization can specify when deploying resources. Use to enforce your geo-compliance requirements. Excludes resource groups, Microsoft.AzureActiveDirectory/b2cDirectories, and resources that use the 'global' region.",
        "mode": "Indexed",
        "parameters": {
            "listOfAllowedLocations": {
                "type": "Array",
                "metadata": {
                    "description": "The list of locations that can be specified when deploying resources.",
                    "strongType": "location",
                    "displayName": "Allowed locations"
                }
            }
        },
        "policyRule": {
            "if": {
                "allOf": [{
                        "field": "location",
                        "notIn": "[parameters('listOfAllowedLocations')]"
                    },
                    {
                        "field": "location",
                        "notEquals": "global"
                    },
                    {
                        "field": "type",
                        "notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
                    }
                ]
            },
            "then": {
                "effect": "Deny"
            }
        }
    }
}

説明

    "if": {
        "allOf": [{
                "field": "location",
                "notIn": "[parameters('listOfAllowedLocations')]"
            },
            {
                "field": "location",
                "notEquals": "global"
            },
            {
                "field": "type",
                "notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
            }
        ]
    },
    "then": {
        "effect": "Deny"
    }
}

field 演算子は論理演算子allOf 内で 3 回使用されています。

  • 最初の使用では、notIn 条件を持つ location プロパティを listOfAllowedLocations パラメーターに評価します。 notIn は、"配列" が想定されるときに機能しますが、実際にこのパラメーターは "配列" です。 作成または更新されるリソースの location が承認済みの一覧に含まれていない場合、この要素は true に評価されます。
  • 2 番目の使用でも location プロパティが評価されますが、notEquals 条件を使用して、リソースが "グローバル" かどうかを確認します。 作成または更新されるリソースの location が "グローバル" でない場合、この要素は true に評価されます。
  • 最後の使用では、type プロパティを評価し、notEquals 条件を使用して、リソースの種類が Microsoft.AzureActiveDirectory/b2cDirectories ではないことを検証します。 そうでない場合、この要素は true に評価されます。

allOf 論理演算子内の 3 つの条件ステートメントすべてが true に評価された場合、リソースの作成または更新は Azure Policy によってブロックされます。

次のステップ