Share via


Azure 原則模式:群組原則定義

方案是一組原則定義。 您可以藉由將相關的原則定義群組到單一物件中,建立有多個指派的單一指派。

範例方案定義

此方案會部署兩個原則定義,每一個都會採用 tagNametagValue 參數。 此方案本身有兩個參數:costCenterValueproductNameValue。 這些方案參數會分別提供給每個已分組的原則定義。 此設計可讓現有原則定義盡可能地重複使用,同時限制建立的指派數目,並在有需要時再加以執行。

{
    "properties": {
        "displayName": "Billing Tags Policy Initiative",
        "description": "Specify cost Center tag and product name tag",
        "parameters": {
            "costCenterValue": {
                "type": "String",
                "metadata": {
                    "displayName": "required value for Cost Center tag"
                }
            },
            "productNameValue": {
                "type": "String",
                "metadata": {
                    "displayName": "required value for product Name tag"
                }
            }
        },
        "policyDefinitions": [{
                "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/1e30110a-5ceb-460c-a204-c1c3969c6d62",
                "parameters": {
                    "tagName": {
                        "value": "costCenter"
                    },
                    "tagValue": {
                        "value": "[parameters('costCenterValue')]"
                    }
                }
            },
            {
                "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498",
                "parameters": {
                    "tagName": {
                        "value": "costCenter"
                    },
                    "tagValue": {
                        "value": "[parameters('costCenterValue')]"
                    }
                }
            },
            {
                "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/1e30110a-5ceb-460c-a204-c1c3969c6d62",
                "parameters": {
                    "tagName": {
                        "value": "productName"
                    },
                    "tagValue": {
                        "value": "[parameters('productNameValue')]"
                    }
                }
            },
            {
                "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498",
                "parameters": {
                    "tagName": {
                        "value": "productName"
                    },
                    "tagValue": {
                        "value": "[parameters('productNameValue')]"
                    }
                }
            }
        ]
    }
}

說明

計畫參數

方案可以定義其自己的參數,然後傳遞至已分組的原則定義。 在此範例中,costCenterValueproductNameValue 都會定義為方案參數。 這些值會在指派方案時提供。

"parameters": {
    "costCenterValue": {
        "type": "String",
        "metadata": {
            "displayName": "required value for Cost Center tag"
        }
    },
    "productNameValue": {
        "type": "String",
        "metadata": {
            "displayName": "required value for product Name tag"
        }
    }
},

包括原則定義

如果原則定義可接受參數,則每個包含的原則定義都必須提供 policyDefinitionId參數陣列。 在下列程式碼片段中,包含的原則定義會採用兩個參數:tagNametagValuetagName 會使用常值來定義,但 tagValue 會使用方案所定義的 costCenterValue 參數。 此值的傳遞可改善重複使用的狀況。

{
    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498",
    "parameters": {
        "tagName": {
            "value": "costCenter"
        },
        "tagValue": {
            "value": "[parameters('costCenterValue')]"
        }
    }
},

下一步