Azure Policy 패턴: 값 연산자

연산자는 매개 변수, 지원되는 템플릿 함수 또는 리터럴을 지정된 조건에 대해 제공된 값으로 평가합니다.

Warning

템플릿 함수의 결과가 오류이면 정책 평가가 실패합니다. 실패한 평가는 암시적 거부입니다. 자세한 내용은 템플릿 오류 방지를 참조하세요.

샘플 정책 정의

이 정책 정의는 리소스의 매개 변수 tagName(string)에 지정된 태그를 추가하거나 바꾸고 리소스가 있는 리소스 그룹에서 tagName의 값을 상속합니다. 이 평가는 리소스를 만들거나 업데이트할 때 발생합니다. 수정 효과로서, 수정 작업을 통해 기존 리소스에서 수정을 실행할 수 있습니다.

{
    "properties": {
        "displayName": "Inherit a tag from the resource group",
        "policyType": "BuiltIn",
        "mode": "Indexed",
        "description": "Adds or replaces the specified tag and value from the parent resource group when any resource is created or updated. Existing resources can be remediated by triggering a remediation task.",
        "metadata": {
            "category": "Tags"
        },
        "parameters": {
            "tagName": {
                "type": "String",
                "metadata": {
                    "displayName": "Tag Name",
                    "description": "Name of the tag, such as 'environment'"
                }
            }
        },
        "policyRule": {
            "if": {
                "allOf": [{
                        "field": "[concat('tags[', parameters('tagName'), ']')]",
                        "notEquals": "[resourceGroup().tags[parameters('tagName')]]"
                    },
                    {
                        "value": "[resourceGroup().tags[parameters('tagName')]]",
                        "notEquals": ""
                    }
                ]
            },
            "then": {
                "effect": "modify",
                "details": {
                    "roleDefinitionIds": [
                        "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
                    ],
                    "operations": [{
                        "operation": "addOrReplace",
                        "field": "[concat('tags[', parameters('tagName'), ']')]",
                        "value": "[resourceGroup().tags[parameters('tagName')]]"
                    }]
                }
            }
        }
    }
}

설명

"if": {
    "allOf": [{
            "field": "[concat('tags[', parameters('tagName'), ']')]",
            "notEquals": "[resourceGroup().tags[parameters('tagName')]]"
        },
        {
            "value": "[resourceGroup().tags[parameters('tagName')]]",
            "notEquals": ""
        }
    ]
},

연산자는 속성 내의 policyRule.if 블록 내에서 사용됩니다. 이 예제에서 논리 연산자allOf수정 효과가 발생하려면 두 조건문이 모두 true이어야 함을 명시하는 데 사용됩니다.

은 템플릿 함수 resourceGroup() 결과를 빈 값의 notEquals 조건으로 평가합니다. 부모 리소스 그룹의 tagName에 제공된 태그 이름이 있으면 조건부가 true로 평가됩니다.

다음 단계