你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
Bicep资源定义
可以使用目标操作部署 policyDefinitions 资源类型:
有关每个 API 版本中已更改属性的列表,请参阅 更改日志。
资源格式
要创建 Microsoft.Authorization/policyDefinitions 资源,请在模板中添加以下 Bicep。
resource symbolicname 'Microsoft.Authorization/policyDefinitions@2025-01-01' = {
name: 'string'
properties: {
description: 'string'
displayName: 'string'
metadata: any(...)
mode: 'string'
parameters: {
{customized property}: {
allowedValues: [
any(...)
]
defaultValue: any(...)
metadata: {
assignPermissions: bool
description: 'string'
displayName: 'string'
strongType: 'string'
}
schema: any(...)
type: 'string'
}
}
policyRule: any(...)
policyType: 'string'
version: 'string'
versions: [
'string'
]
}
}
属性值
Microsoft.Authorization/policyDefinitions
| 名字 | 描述 | 价值 |
|---|---|---|
| 名字 | 资源名称 | 字符串 约束: 模式 = ^[^<>*%&:\?.+/]*[^<>*%&:\?.+/ ]+$ (必需) |
| 性能 | 策略定义属性。 | PolicyDefinitionProperties |
ParameterDefinitions
| 名字 | 描述 | 价值 |
|---|
ParameterDefinitionsValue
| 名字 | 描述 | 价值 |
|---|---|---|
| allowedValues | 参数的允许值。 | any[] |
| defaultValue | 如果未提供任何值,则为参数的默认值。 | 任何 |
| 元数据 | 参数的常规元数据。 | ParameterDefinitionsValueMetadata |
| 架构 | 使用自定义 JSON 架构在分配期间提供参数输入的验证。 该属性仅支持对象类型参数,并遵循 Json.NET 模式 2019-09 实现。 可以在 https://json-schema.org/ 了解有关在 https://www.jsonschemavalidator.net/使用架构的详细信息,并测试草稿架构。 | 任何 |
| 类型 | 参数的数据类型。 | “Array” “Boolean” “DateTime” “Float” “Integer” “Object” “String” |
ParameterDefinitionsValueMetadata
| 名字 | 描述 | 价值 |
|---|---|---|
| assignPermissions | 设置为 true,以便 Azure 门户在策略分配时根据该参数的资源 ID 或资源范围值创建角色分配。 如果要在分配范围之外分配权限,此属性非常有用。 | 布尔 |
| 描述 | 参数的说明。 | 字符串 |
| displayName | 参数的显示名称。 | 字符串 |
| strongType | 通过门户分配策略定义时使用。 提供可供用户选择的值的上下文感知列表。 | 字符串 |
PolicyDefinitionProperties
| 名字 | 描述 | 价值 |
|---|---|---|
| 描述 | 策略定义说明。 | 字符串 |
| displayName | 策略定义的显示名称。 | 字符串 |
| 元数据 | 策略定义元数据。 元数据是一个开放结束的对象,通常是键值对的集合。 | 任何 |
| 模式 | 策略定义模式。 一些示例包括 All、Indexed、Microsoft.KeyVault.Data。 | 字符串 |
| 参数 | 策略规则中使用的参数的参数定义。 键是参数名称。 | ParameterDefinitions |
| policyRule | 策略规则。 | 任何 |
| policyType | 策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。 | “BuiltIn” “Custom” “NotSpecified” “Static” |
| 版本 | #.#.# 格式的策略定义版本。 | 字符串 |
| 版本 | 此策略定义的可用版本列表。 | 字符串[] |
用法示例
Bicep 样本
部署授权策略定义的基本示例。
targetScope = 'subscription'
param resourceName string = 'acctest0001'
resource policyDefinition 'Microsoft.Authorization/policyDefinitions@2021-06-01' = {
name: resourceName
properties: {
description: ''
displayName: 'my-policy-definition'
mode: 'All'
parameters: {
allowedLocations: {
metadata: {
description: 'The list of allowed locations for resources.'
displayName: 'Allowed locations'
strongType: 'location'
}
type: 'Array'
}
}
policyRule: {
if: {
not: {
field: 'location'
in: '[parameters(\'allowedLocations\')]'
}
}
then: {
effect: 'audit'
}
}
policyType: 'Custom'
}
}
Azure 快速入门示例
以下Azure快速启动模板包含部署该资源类型的Bicep示例。
| Bicep 文件 | 描述 |
|---|---|
| 创建一个Azure Virtual Network Manager并采样VNETs | 该模板将Azure Virtual Network Manager和示例虚拟网络部署到指定的资源组中。 它支持多个连接拓扑和网络组成员身份类型。 |
| 部署策略 def,并分配到多个管理组 | 此模板是一个管理组级模板,用于创建策略定义并将该策略分配给多个管理组。 |
| 部署策略定义并分配到管理组 | 此模板是一个管理组级模板,用于创建策略定义并将该策略分配给目标管理组。 目前,该模板无法通过 Azure Portal 部署。 |
ARM 模板资源定义
可以使用目标操作部署 policyDefinitions 资源类型:
有关每个 API 版本中已更改属性的列表,请参阅 更改日志。
资源格式
若要创建 Microsoft.Authorization/policyDefinitions 资源,请将以下 JSON 添加到模板。
{
"type": "Microsoft.Authorization/policyDefinitions",
"apiVersion": "2025-01-01",
"name": "string",
"properties": {
"description": "string",
"displayName": "string",
"metadata": {},
"mode": "string",
"parameters": {
"{customized property}": {
"allowedValues": [ {} ],
"defaultValue": {},
"metadata": {
"assignPermissions": "bool",
"description": "string",
"displayName": "string",
"strongType": "string"
},
"schema": {},
"type": "string"
}
},
"policyRule": {},
"policyType": "string",
"version": "string",
"versions": [ "string" ]
}
}
属性值
Microsoft.Authorization/policyDefinitions
| 名字 | 描述 | 价值 |
|---|---|---|
| apiVersion | API 版本 | '2025-01-01' |
| 名字 | 资源名称 | 字符串 约束: 模式 = ^[^<>*%&:\?.+/]*[^<>*%&:\?.+/ ]+$ (必需) |
| 性能 | 策略定义属性。 | PolicyDefinitionProperties |
| 类型 | 资源类型 | “Microsoft.Authorization/policyDefinitions” |
ParameterDefinitions
| 名字 | 描述 | 价值 |
|---|
ParameterDefinitionsValue
| 名字 | 描述 | 价值 |
|---|---|---|
| allowedValues | 参数的允许值。 | any[] |
| defaultValue | 如果未提供任何值,则为参数的默认值。 | 任何 |
| 元数据 | 参数的常规元数据。 | ParameterDefinitionsValueMetadata |
| 架构 | 使用自定义 JSON 架构在分配期间提供参数输入的验证。 该属性仅支持对象类型参数,并遵循 Json.NET 模式 2019-09 实现。 可以在 https://json-schema.org/ 了解有关在 https://www.jsonschemavalidator.net/使用架构的详细信息,并测试草稿架构。 | 任何 |
| 类型 | 参数的数据类型。 | “Array” “Boolean” “DateTime” “Float” “Integer” “Object” “String” |
ParameterDefinitionsValueMetadata
| 名字 | 描述 | 价值 |
|---|---|---|
| assignPermissions | 设置为 true,以便 Azure 门户在策略分配时根据该参数的资源 ID 或资源范围值创建角色分配。 如果要在分配范围之外分配权限,此属性非常有用。 | 布尔 |
| 描述 | 参数的说明。 | 字符串 |
| displayName | 参数的显示名称。 | 字符串 |
| strongType | 通过门户分配策略定义时使用。 提供可供用户选择的值的上下文感知列表。 | 字符串 |
PolicyDefinitionProperties
| 名字 | 描述 | 价值 |
|---|---|---|
| 描述 | 策略定义说明。 | 字符串 |
| displayName | 策略定义的显示名称。 | 字符串 |
| 元数据 | 策略定义元数据。 元数据是一个开放结束的对象,通常是键值对的集合。 | 任何 |
| 模式 | 策略定义模式。 一些示例包括 All、Indexed、Microsoft.KeyVault.Data。 | 字符串 |
| 参数 | 策略规则中使用的参数的参数定义。 键是参数名称。 | ParameterDefinitions |
| policyRule | 策略规则。 | 任何 |
| policyType | 策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。 | “BuiltIn” “Custom” “NotSpecified” “Static” |
| 版本 | #.#.# 格式的策略定义版本。 | 字符串 |
| 版本 | 此策略定义的可用版本列表。 | 字符串[] |
用法示例
Azure Quickstart Templates
以下Azure快速启动模板部署了这种资源类型。
| 模板 | 描述 |
|---|---|
|
创建一个Azure Virtual Network Manager并采样VNETs |
该模板将Azure Virtual Network Manager和示例虚拟网络部署到指定的资源组中。 它支持多个连接拓扑和网络组成员身份类型。 |
|
部署策略 def,并分配到多个管理组 |
此模板是一个管理组级模板,用于创建策略定义并将该策略分配给多个管理组。 |
|
部署策略定义并分配到管理组 |
此模板是一个管理组级模板,用于创建策略定义并将该策略分配给目标管理组。 目前,该模板无法通过 Azure Portal 部署。 |
Terraform (AzAPI 提供程序)资源定义
可以使用目标操作部署 policyDefinitions 资源类型:
- 管理组* 订阅
有关每个 API 版本中已更改属性的列表,请参阅 更改日志。
资源格式
若要创建 Microsoft.Authorization/policyDefinitions 资源,请将以下 Terraform 添加到模板。
resource "azapi_resource" "symbolicname" {
type = "Microsoft.Authorization/policyDefinitions@2025-01-01"
name = "string"
parent_id = "string"
body = {
properties = {
description = "string"
displayName = "string"
metadata = ?
mode = "string"
parameters = {
{customized property} = {
allowedValues = [
?
]
defaultValue = ?
metadata = {
assignPermissions = bool
description = "string"
displayName = "string"
strongType = "string"
}
schema = ?
type = "string"
}
}
policyRule = ?
policyType = "string"
version = "string"
versions = [
"string"
]
}
}
}
属性值
Microsoft.Authorization/policyDefinitions
| 名字 | 描述 | 价值 |
|---|---|---|
| 名字 | 资源名称 | 字符串 约束: 模式 = ^[^<>*%&:\?.+/]*[^<>*%&:\?.+/ ]+$ (必需) |
| 性能 | 策略定义属性。 | PolicyDefinitionProperties |
| 类型 | 资源类型 | “Microsoft.Authorization/policyDefinitions@2025-01-01” |
ParameterDefinitions
| 名字 | 描述 | 价值 |
|---|
ParameterDefinitionsValue
| 名字 | 描述 | 价值 |
|---|---|---|
| allowedValues | 参数的允许值。 | any[] |
| defaultValue | 如果未提供任何值,则为参数的默认值。 | 任何 |
| 元数据 | 参数的常规元数据。 | ParameterDefinitionsValueMetadata |
| 架构 | 使用自定义 JSON 架构在分配期间提供参数输入的验证。 该属性仅支持对象类型参数,并遵循 Json.NET 模式 2019-09 实现。 可以在 https://json-schema.org/ 了解有关在 https://www.jsonschemavalidator.net/使用架构的详细信息,并测试草稿架构。 | 任何 |
| 类型 | 参数的数据类型。 | “Array” “Boolean” “DateTime” “Float” “Integer” “Object” “String” |
ParameterDefinitionsValueMetadata
| 名字 | 描述 | 价值 |
|---|---|---|
| assignPermissions | 设置为 true,以便 Azure 门户在策略分配时根据该参数的资源 ID 或资源范围值创建角色分配。 如果要在分配范围之外分配权限,此属性非常有用。 | 布尔 |
| 描述 | 参数的说明。 | 字符串 |
| displayName | 参数的显示名称。 | 字符串 |
| strongType | 通过门户分配策略定义时使用。 提供可供用户选择的值的上下文感知列表。 | 字符串 |
PolicyDefinitionProperties
| 名字 | 描述 | 价值 |
|---|---|---|
| 描述 | 策略定义说明。 | 字符串 |
| displayName | 策略定义的显示名称。 | 字符串 |
| 元数据 | 策略定义元数据。 元数据是一个开放结束的对象,通常是键值对的集合。 | 任何 |
| 模式 | 策略定义模式。 一些示例包括 All、Indexed、Microsoft.KeyVault.Data。 | 字符串 |
| 参数 | 策略规则中使用的参数的参数定义。 键是参数名称。 | ParameterDefinitions |
| policyRule | 策略规则。 | 任何 |
| policyType | 策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。 | “BuiltIn” “Custom” “NotSpecified” “Static” |
| 版本 | #.#.# 格式的策略定义版本。 | 字符串 |
| 版本 | 此策略定义的可用版本列表。 | 字符串[] |
用法示例
Terraform 示例
部署授权策略定义的基本示例。
terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
azurerm = {
source = "hashicorp/azurerm"
}
}
}
provider "azurerm" {
features {
}
}
provider "azapi" {
skip_provider_registration = false
}
variable "resource_name" {
type = string
default = "acctest0001"
}
variable "location" {
type = string
default = "eastus"
}
data "azurerm_client_config" "current" {
}
resource "azapi_resource" "policyDefinition" {
type = "Microsoft.Authorization/policyDefinitions@2021-06-01"
parent_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
name = var.resource_name
body = {
properties = {
description = ""
displayName = "my-policy-definition"
mode = "All"
parameters = {
allowedLocations = {
metadata = {
description = "The list of allowed locations for resources."
displayName = "Allowed locations"
strongType = "location"
}
type = "Array"
}
}
policyRule = {
if = {
not = {
field = "location"
in = "[parameters('allowedLocations')]"
}
}
then = {
effect = "audit"
}
}
policyType = "Custom"
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}