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 参数
| 名称 | 在 | 必需 | 类型 | 说明 |
|---|---|---|---|---|
|
management
|
path | True |
string |
管理组的 ID。 |
|
policy
|
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,
Parameter |
策略规则中使用的参数的参数定义。 键是参数名称。 |
| properties.policyRule |
object |
策略规则。 |
| properties.policyType |
策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。 |
|
| properties.version |
string |
#.#.# 格式的策略定义版本。 |
| properties.versions |
string[] |
此策略定义的可用版本列表。 |
响应
| 名称 | 类型 | 说明 |
|---|---|---|
| 201 Created |
创建 - 返回有关策略定义的信息。 |
|
| Other Status Codes |
描述操作失败的原因的错误响应。 |
安全性
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"
}
}
定义
| 名称 | 说明 |
|---|---|
|
Cloud |
策略操作的错误响应。 |
|
created |
创建资源的标识的类型。 |
|
Error |
资源管理错误附加信息。 |
|
Error |
错误响应 |
| Metadata |
参数的常规元数据。 |
|
Parameter |
可以提供给策略的参数的定义。 |
|
parameter |
参数的数据类型。 |
|
Policy |
策略定义。 |
|
policy |
策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。 |
|
system |
与创建和上次修改资源相关的元数据。 |
CloudError
策略操作的错误响应。
| 名称 | 类型 | 说明 |
|---|---|---|
| error |
错误响应 |
createdByType
创建资源的标识的类型。
| 值 | 说明 |
|---|---|
| User | |
| Application | |
| ManagedIdentity | |
| Key |
ErrorAdditionalInfo
资源管理错误附加信息。
| 名称 | 类型 | 说明 |
|---|---|---|
| info |
object |
其他信息。 |
| type |
string |
其他信息类型。 |
ErrorResponse
错误响应
| 名称 | 类型 | 说明 |
|---|---|---|
| additionalInfo |
错误附加信息。 |
|
| code |
string |
错误代码。 |
| details |
错误详细信息。 |
|
| message |
string |
错误消息。 |
| target |
string |
错误目标。 |
Metadata
参数的常规元数据。
| 名称 | 类型 | 说明 |
|---|---|---|
| assignPermissions |
boolean |
设置为 true,让 Azure 门户在策略分配期间基于此参数的资源 ID 或资源范围值创建角色分配。 如果要在分配范围之外分配权限,此属性非常有用。 |
| description |
string |
参数的说明。 |
| displayName |
string |
参数的显示名称。 |
| strongType |
string |
通过门户分配策略定义时使用。 提供可供用户选择的值的上下文感知列表。 |
ParameterDefinitionsValue
可以提供给策略的参数的定义。
| 名称 | 类型 | 说明 |
|---|---|---|
| allowedValues |
object[] |
参数的允许值。 |
| defaultValue |
object |
如果未提供任何值,则为参数的默认值。 |
| metadata |
参数的常规元数据。 |
|
| schema |
object |
使用自定义 JSON 架构在分配期间提供参数输入的验证。 此属性仅支持对象类型参数,并遵循 Json.NET Schema 2019-09 实现。 可以在 https://json-schema.org/ 了解有关在 https://www.jsonschemavalidator.net/使用架构的详细信息,并测试草稿架构。 |
| type |
参数的数据类型。 |
parameterType
参数的数据类型。
| 值 | 说明 |
|---|---|
| String | |
| Array | |
| Object | |
| Boolean | |
| Integer | |
| Float | |
| DateTime |
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,
Parameter |
策略规则中使用的参数的参数定义。 键是参数名称。 |
|
| properties.policyRule |
object |
策略规则。 |
|
| properties.policyType |
策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。 |
||
| properties.version |
string |
#.#.# 格式的策略定义版本。 |
|
| properties.versions |
string[] |
此策略定义的可用版本列表。 |
|
| systemData |
与此资源相关的系统元数据。 |
||
| type |
string |
资源的类型(Microsoft.Authorization/policyDefinitions)。 |
policyType
策略定义的类型。 可能的值为 NotSpecified、BuiltIn、Custom 和 Static。
| 值 | 说明 |
|---|---|
| NotSpecified | |
| BuiltIn | |
| Custom | |
| Static |
systemData
与创建和上次修改资源相关的元数据。
| 名称 | 类型 | 说明 |
|---|---|---|
| createdAt |
string (date-time) |
资源创建时间戳(UTC)。 |
| createdBy |
string |
创建资源的标识。 |
| createdByType |
创建资源的标识的类型。 |
|
| lastModifiedAt |
string (date-time) |
上次修改的资源时间戳(UTC) |
| lastModifiedBy |
string |
上次修改资源的标识。 |
| lastModifiedByType |
上次修改资源的标识的类型。 |