Azure Policy 패턴: 필드 속성

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 내에서 세 번 사용됩니다.

  • 첫 번째 용도는 notIn 조건이 있는 location 속성을 listOfAllowedLocations 매개 변수로 평가합니다. notIn배열이 필요한 만큼 작동하며 매개 변수는 배열입니다. 생성되거나 업데이트된 리소스의 location이 승인된 목록에 없는 경우 이 요소는 true로 평가됩니다.
  • 두 번째 용도는 location 속성도 평가하지만 notEquals 조건을 사용하여 리소스가 글로벌인지 확인합니다. 생성되거나 업데이트된 리소스의 location글로벌이 아닌 경우 이 요소는 true로 평가됩니다.
  • 마지막 용도는 type 속성을 평가하고 notEquals 조건을 사용하여 리소스 형식이 Microsoft.AzureActiveDirectory/b2cDirectories가 아닌지 확인합니다. 그렇지 않은 경우 이 요소는 true로 평가됩니다.

allOf 논리 연산자의 세 조건문이 모두 true로 평가되면 리소스 생성 또는 업데이트는 Azure Policy에 의해 차단됩니다.

다음 단계