通过


你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Microsoft.授权策略定义 2018-05-01

Bicep资源定义

可以使用目标操作部署 policyDefinitions 资源类型:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

要创建 Microsoft.Authorization/policyDefinitions 资源,请在模板中添加以下 Bicep。

resource symbolicname 'Microsoft.Authorization/policyDefinitions@2018-05-01' = {
  name: 'string'
  properties: {
    description: 'string'
    displayName: 'string'
    metadata: any(...)
    mode: 'string'
    parameters: any(...)
    policyRule: any(...)
    policyType: 'string'
  }
}

属性值

Microsoft.Authorization/policyDefinitions

名字 描述 价值
名字 资源名称 string (必需)
性能 策略定义属性。 PolicyDefinitionProperties

PolicyDefinitionProperties

名字 描述 价值
描述 策略定义说明。 字符串
displayName 策略定义的显示名称。 字符串
元数据 策略定义元数据。 任何
模式 策略定义模式。 可能的值为 NotSpecified、Indexed 和 All。 “All”
“Indexed”
“NotSpecified”
参数 如果在策略规则中使用参数,则为必需参数。 任何
policyRule 策略规则。 任何
policyType 策略定义的类型。 可能的值为 NotSpecified、BuiltIn 和 Custom。 “BuiltIn”
“Custom”
“NotSpecified”

用法示例

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": "2018-05-01",
  "name": "string",
  "properties": {
    "description": "string",
    "displayName": "string",
    "metadata": {},
    "mode": "string",
    "parameters": {},
    "policyRule": {},
    "policyType": "string"
  }
}

属性值

Microsoft.Authorization/policyDefinitions

名字 描述 价值
apiVersion API 版本 '2018-05-01'
名字 资源名称 string (必需)
性能 策略定义属性。 PolicyDefinitionProperties
类型 资源类型 “Microsoft.Authorization/policyDefinitions”

PolicyDefinitionProperties

名字 描述 价值
描述 策略定义说明。 字符串
displayName 策略定义的显示名称。 字符串
元数据 策略定义元数据。 任何
模式 策略定义模式。 可能的值为 NotSpecified、Indexed 和 All。 “All”
“Indexed”
“NotSpecified”
参数 如果在策略规则中使用参数,则为必需参数。 任何
policyRule 策略规则。 任何
policyType 策略定义的类型。 可能的值为 NotSpecified、BuiltIn 和 Custom。 “BuiltIn”
“Custom”
“NotSpecified”

用法示例

Azure Quickstart Templates

以下Azure快速启动模板部署了这种资源类型。

模板 描述
创建一个Azure Virtual Network Manager并采样VNETs

部署到Azure
该模板将Azure Virtual Network Manager和示例虚拟网络部署到指定的资源组中。 它支持多个连接拓扑和网络组成员身份类型。
部署策略 def,并分配到多个管理组

部署到Azure
此模板是一个管理组级模板,用于创建策略定义并将该策略分配给多个管理组。
部署策略定义并分配到管理组

部署到Azure
此模板是一个管理组级模板,用于创建策略定义并将该策略分配给目标管理组。 目前,该模板无法通过 Azure Portal 部署。

Terraform (AzAPI 提供程序)资源定义

可以使用目标操作部署 policyDefinitions 资源类型:

  • 管理组* 订阅

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.Authorization/policyDefinitions 资源,请将以下 Terraform 添加到模板。

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.Authorization/policyDefinitions@2018-05-01"
  name = "string"
  parent_id = "string"
  body = {
    properties = {
      description = "string"
      displayName = "string"
      metadata = ?
      mode = "string"
      parameters = ?
      policyRule = ?
      policyType = "string"
    }
  }
}

属性值

Microsoft.Authorization/policyDefinitions

名字 描述 价值
名字 资源名称 string (必需)
性能 策略定义属性。 PolicyDefinitionProperties
类型 资源类型 “Microsoft.Authorization/policyDefinitions@2018-05-01”

PolicyDefinitionProperties

名字 描述 价值
描述 策略定义说明。 字符串
displayName 策略定义的显示名称。 字符串
元数据 策略定义元数据。 任何
模式 策略定义模式。 可能的值为 NotSpecified、Indexed 和 All。 “All”
“Indexed”
“NotSpecified”
参数 如果在策略规则中使用参数,则为必需参数。 任何
policyRule 策略规则。 任何
policyType 策略定义的类型。 可能的值为 NotSpecified、BuiltIn 和 Custom。 “BuiltIn”
“Custom”
“NotSpecified”

用法示例

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    = ["*"]
}