Bicep 资源定义
可以使用目标操作部署 policyAssignments 资源类型:
有关每个 API 版本中已更改属性的列表,请参阅 更改日志。
若要创建 Microsoft.Authorization/policyAssignments 资源,请将以下 Bicep 添加到模板。
resource symbolicname 'Microsoft.Authorization/policyAssignments@2022-06-01' = {
scope: resourceSymbolicName or scope
identity: {
type: 'string'
userAssignedIdentities: {
{customized property}: {}
}
}
location: 'string'
name: 'string'
properties: {
description: 'string'
displayName: 'string'
enforcementMode: 'string'
metadata: any(...)
nonComplianceMessages: [
{
message: 'string'
policyDefinitionReferenceId: 'string'
}
]
notScopes: [
'string'
]
overrides: [
{
kind: 'string'
selectors: [
{
in: [
'string'
]
kind: 'string'
notIn: [
'string'
]
}
]
value: 'string'
}
]
parameters: {
{customized property}: {
value: any(...)
}
}
policyDefinitionId: 'string'
resourceSelectors: [
{
name: 'string'
selectors: [
{
in: [
'string'
]
kind: 'string'
notIn: [
'string'
]
}
]
}
]
}
}
属性值
Microsoft.Authorization/policyAssignments
| 名字 |
描述 |
价值 |
| 标识 |
与策略分配关联的托管标识。 |
标识 |
| 位置 |
策略分配的位置。 仅当使用托管标识时才需要。 |
字符串 |
| 名字 |
资源名称 |
string (必需) |
| 性能 |
策略分配的属性。 |
PolicyAssignmentProperties |
| 作用域 |
在与部署范围不同的范围内创建资源时使用。 |
将此属性设置为资源的符号名称,以应用 扩展资源。 |
身份
| 名字 |
描述 |
价值 |
| 类型 |
标识类型。 这是将系统或用户分配的标识添加到资源时的唯一必填字段。 |
“None” “SystemAssigned” “UserAssigned” |
| 用户分配的标识 |
与策略关联的用户标识。 用户标识字典密钥引用的格式为 ARM 资源 ID:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 |
IdentityUserAssignedIdentities |
IdentityUserAssignedIdentities
不合规消息
| 名字 |
描述 |
价值 |
| 消息 |
描述资源不符合策略的原因的消息。 这会显示在“拒绝”错误消息中,以及资源的不符合符合性结果。 |
string (必需) |
| policyDefinitionReferenceId |
消息适用于的策略集定义中的策略定义引用 ID。 这仅适用于策略分配分配策略集定义。 如果未提供此消息,则消息适用于此策略分配分配的所有策略。 |
字符串 |
覆盖
| 名字 |
描述 |
价值 |
| 类 |
重写类型。 |
“policyEffect” |
| 选择 |
选择器表达式的列表。 |
选择器[] |
| 价值 |
要重写策略属性的值。 |
字符串 |
参数值
参数值值
PolicyAssignmentProperties
| 名字 |
描述 |
价值 |
| 描述 |
如果发生策略冲突,此消息将是响应的一部分。 |
字符串 |
| displayName (显示名称) |
策略分配的显示名称。 |
字符串 |
| enforcementMode |
策略分配强制模式。 可能的值为 Default 和 DoNotEnforce。 |
“Default” “DoNotEnforce” |
| 元数据 |
策略分配元数据。 元数据是一个开放结束的对象,通常是键值对的集合。 |
任何 |
| nonComplianceMessages |
描述资源不符合策略的原因的消息。 |
NoncomplianceMessage[] |
| notScopes |
策略的排除范围。 |
字符串[] |
| 重写 |
策略属性值重写。 |
替代[] |
| 参数 |
分配的策略规则的参数值。 键是参数名称。 |
参数值 |
| policyDefinitionId |
要分配的策略定义或策略集定义的 ID。 |
字符串 |
| resourceSelectors |
按资源属性筛选策略的资源选择器列表。 |
资源选择器 |
资源选择器
| 名字 |
描述 |
价值 |
| 名字 |
资源选择器的名称。 |
字符串 |
| 选择 |
选择器表达式的列表。 |
选择器[] |
选择器
| 名字 |
描述 |
价值 |
| 在 |
要筛选的值列表。 |
字符串[] |
| 类 |
选择器类型。 |
“policyDefinitionReferenceId” “resourceLocation” “resourceType” “resourceWithoutLocation” |
| notIn |
要筛选出的值列表。 |
字符串[] |
UserAssignedIdentitiesValue
用法示例
Bicep 示例
部署策略分配的基本示例。
targetScope = 'subscription'
param resourceName string = 'acctest0001'
resource policyAssignment 'Microsoft.Authorization/policyAssignments@2022-06-01' = {
name: resourceName
properties: {
displayName: ''
enforcementMode: 'Default'
parameters: {
listOfAllowedLocations: {
value: [
'West Europe'
'West US 2'
'East US 2'
]
}
}
policyDefinitionId: policyDefinition.id
scope: subscription().id
}
}
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 验证模块 可用于部署此资源类型。
Azure 快速入门示例
以下 Azure 快速入门模板 包含用于部署此资源类型的 Bicep 示例。
ARM 模板资源定义
可以使用目标操作部署 policyAssignments 资源类型:
有关每个 API 版本中已更改属性的列表,请参阅 更改日志。
若要创建 Microsoft.Authorization/policyAssignments 资源,请将以下 JSON 添加到模板。
{
"type": "Microsoft.Authorization/policyAssignments",
"apiVersion": "2022-06-01",
"name": "string",
"identity": {
"type": "string",
"userAssignedIdentities": {
"{customized property}": {
}
}
},
"location": "string",
"properties": {
"description": "string",
"displayName": "string",
"enforcementMode": "string",
"metadata": {},
"nonComplianceMessages": [
{
"message": "string",
"policyDefinitionReferenceId": "string"
}
],
"notScopes": [ "string" ],
"overrides": [
{
"kind": "string",
"selectors": [
{
"in": [ "string" ],
"kind": "string",
"notIn": [ "string" ]
}
],
"value": "string"
}
],
"parameters": {
"{customized property}": {
"value": {}
}
},
"policyDefinitionId": "string",
"resourceSelectors": [
{
"name": "string",
"selectors": [
{
"in": [ "string" ],
"kind": "string",
"notIn": [ "string" ]
}
]
}
]
}
}
属性值
Microsoft.Authorization/policyAssignments
| 名字 |
描述 |
价值 |
| apiVersion |
API 版本 |
'2022-06-01' |
| 标识 |
与策略分配关联的托管标识。 |
标识 |
| 位置 |
策略分配的位置。 仅当使用托管标识时才需要。 |
字符串 |
| 名字 |
资源名称 |
string (必需) |
| 性能 |
策略分配的属性。 |
PolicyAssignmentProperties |
| 类型 |
资源类型 |
“Microsoft.Authorization/policyAssignments” |
身份
| 名字 |
描述 |
价值 |
| 类型 |
标识类型。 这是将系统或用户分配的标识添加到资源时的唯一必填字段。 |
“None” “SystemAssigned” “UserAssigned” |
| 用户分配的标识 |
与策略关联的用户标识。 用户标识字典密钥引用的格式为 ARM 资源 ID:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 |
IdentityUserAssignedIdentities |
IdentityUserAssignedIdentities
不合规消息
| 名字 |
描述 |
价值 |
| 消息 |
描述资源不符合策略的原因的消息。 这会显示在“拒绝”错误消息中,以及资源的不符合符合性结果。 |
string (必需) |
| policyDefinitionReferenceId |
消息适用于的策略集定义中的策略定义引用 ID。 这仅适用于策略分配分配策略集定义。 如果未提供此消息,则消息适用于此策略分配分配的所有策略。 |
字符串 |
覆盖
| 名字 |
描述 |
价值 |
| 类 |
重写类型。 |
“policyEffect” |
| 选择 |
选择器表达式的列表。 |
选择器[] |
| 价值 |
要重写策略属性的值。 |
字符串 |
参数值
参数值值
PolicyAssignmentProperties
| 名字 |
描述 |
价值 |
| 描述 |
如果发生策略冲突,此消息将是响应的一部分。 |
字符串 |
| displayName (显示名称) |
策略分配的显示名称。 |
字符串 |
| enforcementMode |
策略分配强制模式。 可能的值为 Default 和 DoNotEnforce。 |
“Default” “DoNotEnforce” |
| 元数据 |
策略分配元数据。 元数据是一个开放结束的对象,通常是键值对的集合。 |
任何 |
| nonComplianceMessages |
描述资源不符合策略的原因的消息。 |
NoncomplianceMessage[] |
| notScopes |
策略的排除范围。 |
字符串[] |
| 重写 |
策略属性值重写。 |
替代[] |
| 参数 |
分配的策略规则的参数值。 键是参数名称。 |
参数值 |
| policyDefinitionId |
要分配的策略定义或策略集定义的 ID。 |
字符串 |
| resourceSelectors |
按资源属性筛选策略的资源选择器列表。 |
资源选择器 |
资源选择器
| 名字 |
描述 |
价值 |
| 名字 |
资源选择器的名称。 |
字符串 |
| 选择 |
选择器表达式的列表。 |
选择器[] |
选择器
| 名字 |
描述 |
价值 |
| 在 |
要筛选的值列表。 |
字符串[] |
| 类 |
选择器类型。 |
“policyDefinitionReferenceId” “resourceLocation” “resourceType” “resourceWithoutLocation” |
| notIn |
要筛选出的值列表。 |
字符串[] |
UserAssignedIdentitiesValue
用法示例
Azure 快速入门模板
以下 Azure 快速入门模板 部署此资源类型。
可以使用目标操作部署 policyAssignments 资源类型:
有关每个 API 版本中已更改属性的列表,请参阅 更改日志。
若要创建 Microsoft.Authorization/policyAssignments 资源,请将以下 Terraform 添加到模板。
resource "azapi_resource" "symbolicname" {
type = "Microsoft.Authorization/policyAssignments@2022-06-01"
name = "string"
parent_id = "string"
identity {
type = "string"
identity_ids = [
"string"
]
}
location = "string"
body = {
properties = {
description = "string"
displayName = "string"
enforcementMode = "string"
metadata = ?
nonComplianceMessages = [
{
message = "string"
policyDefinitionReferenceId = "string"
}
]
notScopes = [
"string"
]
overrides = [
{
kind = "string"
selectors = [
{
in = [
"string"
]
kind = "string"
notIn = [
"string"
]
}
]
value = "string"
}
]
parameters = {
{customized property} = {
value = ?
}
}
policyDefinitionId = "string"
resourceSelectors = [
{
name = "string"
selectors = [
{
in = [
"string"
]
kind = "string"
notIn = [
"string"
]
}
]
}
]
}
}
}
属性值
Microsoft.Authorization/policyAssignments
| 名字 |
描述 |
价值 |
| 标识 |
与策略分配关联的托管标识。 |
标识 |
| 位置 |
策略分配的位置。 仅当使用托管标识时才需要。 |
字符串 |
| 名字 |
资源名称 |
string (必需) |
| parent_id |
要向其应用此扩展资源的资源的 ID。 |
string (必需) |
| 性能 |
策略分配的属性。 |
PolicyAssignmentProperties |
| 类型 |
资源类型 |
“Microsoft.Authorization/policyAssignments@2022-06-01” |
身份
| 名字 |
描述 |
价值 |
| 类型 |
标识类型。 这是将系统或用户分配的标识添加到资源时的唯一必填字段。 |
“None” “SystemAssigned” “UserAssigned” |
| 用户分配的标识 |
与策略关联的用户标识。 用户标识字典密钥引用的格式为 ARM 资源 ID:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 |
IdentityUserAssignedIdentities |
IdentityUserAssignedIdentities
不合规消息
| 名字 |
描述 |
价值 |
| 消息 |
描述资源不符合策略的原因的消息。 这会显示在“拒绝”错误消息中,以及资源的不符合符合性结果。 |
string (必需) |
| policyDefinitionReferenceId |
消息适用于的策略集定义中的策略定义引用 ID。 这仅适用于策略分配分配策略集定义。 如果未提供此消息,则消息适用于此策略分配分配的所有策略。 |
字符串 |
覆盖
| 名字 |
描述 |
价值 |
| 类 |
重写类型。 |
“policyEffect” |
| 选择 |
选择器表达式的列表。 |
选择器[] |
| 价值 |
要重写策略属性的值。 |
字符串 |
参数值
参数值值
PolicyAssignmentProperties
| 名字 |
描述 |
价值 |
| 描述 |
如果发生策略冲突,此消息将是响应的一部分。 |
字符串 |
| displayName (显示名称) |
策略分配的显示名称。 |
字符串 |
| enforcementMode |
策略分配强制模式。 可能的值为 Default 和 DoNotEnforce。 |
“Default” “DoNotEnforce” |
| 元数据 |
策略分配元数据。 元数据是一个开放结束的对象,通常是键值对的集合。 |
任何 |
| nonComplianceMessages |
描述资源不符合策略的原因的消息。 |
NoncomplianceMessage[] |
| notScopes |
策略的排除范围。 |
字符串[] |
| 重写 |
策略属性值重写。 |
替代[] |
| 参数 |
分配的策略规则的参数值。 键是参数名称。 |
参数值 |
| policyDefinitionId |
要分配的策略定义或策略集定义的 ID。 |
字符串 |
| resourceSelectors |
按资源属性筛选策略的资源选择器列表。 |
资源选择器 |
资源选择器
| 名字 |
描述 |
价值 |
| 名字 |
资源选择器的名称。 |
字符串 |
| 选择 |
选择器表达式的列表。 |
选择器[] |
选择器
| 名字 |
描述 |
价值 |
| 在 |
要筛选的值列表。 |
字符串[] |
| 类 |
选择器类型。 |
“policyDefinitionReferenceId” “resourceLocation” “resourceType” “resourceWithoutLocation” |
| notIn |
要筛选出的值列表。 |
字符串[] |
UserAssignedIdentitiesValue
用法示例
部署策略分配的基本示例。
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" {
}
data "azapi_resource" "subscription" {
type = "Microsoft.Resources/subscriptions@2021-01-01"
resource_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
response_export_values = ["*"]
}
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 = ["*"]
}
resource "azapi_resource" "policyAssignment" {
type = "Microsoft.Authorization/policyAssignments@2022-06-01"
parent_id = data.azapi_resource.subscription.id
name = var.resource_name
body = {
properties = {
displayName = ""
enforcementMode = "Default"
parameters = {
listOfAllowedLocations = {
value = [
"West Europe",
"West US 2",
"East US 2",
]
}
}
policyDefinitionId = azapi_resource.policyDefinition.id
scope = data.azapi_resource.subscription.id
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}