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

Policy Definitions - Create Or Update At Management Group

在管理组中创建或更新策略定义。
此操作使用给定名称在给定的管理组中创建或更新策略定义。

PUT https://management.azure.com/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}?api-version=2023-04-01

URI 参数

名称 必需 类型 说明
managementGroupId
path True

string

管理组的 ID。

policyDefinitionName
path True

string

pattern: ^[^<>*%&:\?.+/]*[^<>*%&:\?.+/ ]+$

要创建的策略定义的名称。

api-version
query True

string

minLength: 1

用于此操作的 API 版本。

请求正文

名称 类型 说明
properties.description

string

策略定义说明。

properties.displayName

string

策略定义的显示名称。

properties.metadata

object

策略定义元数据。 元数据是一个开放结束的对象,通常是键值对的集合。

properties.mode

string

策略定义模式。 一些示例包括 All、Indexed、Microsoft.KeyVault.Data。

properties.parameters

<string,  ParameterDefinitionsValue>

策略规则中使用的参数的参数定义。 键是参数名称。

properties.policyRule

object

策略规则。

properties.policyType

policyType

策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。

properties.version

string

#.#.# 格式的策略定义版本。

properties.versions

string[]

此策略定义的可用版本列表。

响应

名称 类型 说明
201 Created

PolicyDefinition

创建 - 返回有关策略定义的信息。

Other Status Codes

CloudError

描述操作失败的原因的错误响应。

安全性

azure_auth

Azure Active Directory OAuth2 Flow。

类型: oauth2
流向: implicit
授权 URL: https://login.microsoftonline.com/common/oauth2/authorize

作用域

名称 说明
user_impersonation 模拟用户帐户

示例

Create or update a policy definition at management group level

示例请求

PUT https://management.azure.com/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming?api-version=2023-04-01

{
  "properties": {
    "mode": "All",
    "displayName": "Enforce resource naming convention",
    "description": "Force resource names to begin with given 'prefix' and/or end with given 'suffix'",
    "metadata": {
      "category": "Naming"
    },
    "policyRule": {
      "if": {
        "not": {
          "field": "name",
          "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]"
        }
      },
      "then": {
        "effect": "deny"
      }
    },
    "parameters": {
      "prefix": {
        "type": "String",
        "metadata": {
          "displayName": "Prefix",
          "description": "Resource name prefix"
        }
      },
      "suffix": {
        "type": "String",
        "metadata": {
          "displayName": "Suffix",
          "description": "Resource name suffix"
        }
      }
    }
  }
}

示例响应

{
  "id": "/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming",
  "type": "Microsoft.Authorization/policyDefinitions",
  "name": "ResourceNaming",
  "properties": {
    "mode": "All",
    "displayName": "Naming Convention",
    "description": "Force resource names to begin with 'prefix' and end with 'suffix'",
    "metadata": {
      "category": "Naming"
    },
    "version": "1.2.1",
    "versions": [
      "1.2.1",
      "1.0.0"
    ],
    "policyRule": {
      "if": {
        "not": {
          "field": "name",
          "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]"
        }
      },
      "then": {
        "effect": "deny"
      }
    },
    "parameters": {
      "prefix": {
        "type": "String",
        "metadata": {
          "displayName": "Prefix",
          "description": "Resource name prefix"
        }
      },
      "suffix": {
        "type": "String",
        "metadata": {
          "displayName": "Suffix",
          "description": "Resource name suffix"
        }
      }
    },
    "policyType": "Custom"
  }
}

定义

名称 说明
CloudError

策略操作的错误响应。

createdByType

创建资源的标识的类型。

ErrorAdditionalInfo

资源管理错误附加信息。

ErrorResponse

错误响应

Metadata

参数的常规元数据。

ParameterDefinitionsValue

可以提供给策略的参数的定义。

parameterType

参数的数据类型。

PolicyDefinition

策略定义。

policyType

策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。

systemData

与创建和上次修改资源相关的元数据。

CloudError

策略操作的错误响应。

名称 类型 说明
error

ErrorResponse

错误响应
所有 Azure 资源管理器 API 的常见错误响应,以返回失败操作的错误详细信息。 (这也遵循 OData 错误响应格式。)

createdByType

创建资源的标识的类型。

说明
Application
Key
ManagedIdentity
User

ErrorAdditionalInfo

资源管理错误附加信息。

名称 类型 说明
info

object

其他信息。

type

string

其他信息类型。

ErrorResponse

错误响应

名称 类型 说明
additionalInfo

ErrorAdditionalInfo[]

错误附加信息。

code

string

错误代码。

details

ErrorResponse[]

错误详细信息。

message

string

错误消息。

target

string

错误目标。

Metadata

参数的常规元数据。

名称 类型 说明
assignPermissions

boolean

设置为 true,让 Azure 门户在策略分配期间基于此参数的资源 ID 或资源范围值创建角色分配。 如果要在分配范围之外分配权限,此属性非常有用。

description

string

参数的说明。

displayName

string

参数的显示名称。

strongType

string

通过门户分配策略定义时使用。 提供可供用户选择的值的上下文感知列表。

ParameterDefinitionsValue

可以提供给策略的参数的定义。

名称 类型 说明
allowedValues

object[]

参数的允许值。

defaultValue

object

如果未提供任何值,则为参数的默认值。

metadata

Metadata

参数的常规元数据。

schema

object

使用自定义 JSON 架构在分配期间提供参数输入的验证。 此属性仅支持对象类型参数,并遵循 Json.NET Schema 2019-09 实现。 可以在 https://json-schema.org/ 了解有关在 https://www.jsonschemavalidator.net/使用架构的详细信息,并测试草稿架构。

type

parameterType

参数的数据类型。

parameterType

参数的数据类型。

说明
Array
Boolean
DateTime
Float
Integer
Object
String

PolicyDefinition

策略定义。

名称 类型 默认值 说明
id

string

策略定义的 ID。

name

string

策略定义的名称。

properties.description

string

策略定义说明。

properties.displayName

string

策略定义的显示名称。

properties.metadata

object

策略定义元数据。 元数据是一个开放结束的对象,通常是键值对的集合。

properties.mode

string

Indexed

策略定义模式。 一些示例包括 All、Indexed、Microsoft.KeyVault.Data。

properties.parameters

<string,  ParameterDefinitionsValue>

策略规则中使用的参数的参数定义。 键是参数名称。

properties.policyRule

object

策略规则。

properties.policyType

policyType

策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。

properties.version

string

#.#.# 格式的策略定义版本。

properties.versions

string[]

此策略定义的可用版本列表。

systemData

systemData

与此资源相关的系统元数据。

type

string

资源的类型(Microsoft.Authorization/policyDefinitions)。

policyType

策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。

说明
BuiltIn
Custom
NotSpecified
Static

systemData

与创建和上次修改资源相关的元数据。

名称 类型 说明
createdAt

string (date-time)

资源创建时间戳(UTC)。

createdBy

string

创建资源的标识。

createdByType

createdByType

创建资源的标识的类型。

lastModifiedAt

string (date-time)

上次修改的资源时间戳(UTC)

lastModifiedBy

string

上次修改资源的标识。

lastModifiedByType

createdByType

上次修改资源的标识的类型。