共用方式為


Policy Assignments - Create By Id

建立或更新原則指派。
此操作會建立或更新與指定 ID 的政策指派。 針對範圍所做的政策指派,適用於該範圍內的所有資源。 例如,當你將政策指派給資源群組時,該政策適用於該群組中的所有資源。 政策指派 ID 格式為:'{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'。 有效的作用域包括:管理群組(格式:'/providers/Microsoft.Management/managementGroups/{managementGroup}')、訂閱(格式:'/subscriptions/{subscriptionId}')、資源群組(格式:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}'),或資源(格式:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}''。

PUT https://management.azure.com/{policyAssignmentId}?api-version=2025-01-01

URI 參數

名稱 位於 必要 類型 Description
policyAssignmentId
path True

string

要建立的政策指派的 ID。 使用格式 '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'。

api-version
query True

string

minLength: 1

用於此作業的 API 版本。

要求本文

名稱 類型 Description
identity

Identity

與原則指派相關聯的受控識別。

location

string

原則指派的位置。 只有在使用受控識別時才需要。

properties.assignmentType

assignmentType

原則指派的類型。 可能的值為 NotSpecified、System、SystemHidden 和 Custom。 變。

properties.definitionVersion

string

要使用的原則定義版本。

properties.description

string

如果違反原則,此訊息將會是回應的一部分。

properties.displayName

string

原則指派的顯示名稱。

properties.enforcementMode

enforcementMode

原則指派強制模式。 可能的值為 Default、DoNotEnforce 和 Enroll

properties.metadata

object

原則指派元數據。 元數據是開放式物件,通常是索引鍵值組的集合。

properties.nonComplianceMessages

NonComplianceMessage[]

描述資源不符合原則之原因的訊息。

properties.notScopes

string[]

原則的排除範圍。

properties.overrides

Override[]

原則屬性值覆寫。

properties.parameters

<string,  ParameterValuesValue>

指派原則規則的參數值。 索引鍵是參數名稱。

properties.policyDefinitionId

string

要指派的原則定義或原則集定義的標識碼。

properties.resourceSelectors

ResourceSelector[]

依資源屬性篩選原則的資源選取器清單。

回應

名稱 類型 Description
201 Created

PolicyAssignment

已建立 - 回傳關於政策指派的資訊。

Other Status Codes

CloudError

描述作業失敗原因的錯誤回應。

安全性

azure_auth

Azure Active Directory OAuth2 Flow.

類型: oauth2
Flow: implicit
授權 URL: https://login.microsoftonline.com/common/oauth2/authorize

範圍

名稱 Description
user_impersonation 模擬您的用戶帳戶

範例

Create or update policy assignment by ID
Create or update policy assignment with a managed identity by ID

Create or update policy assignment by ID

範例要求

PUT https://management.azure.com/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage?api-version=2025-01-01

{
  "properties": {
    "displayName": "Enforce storage account SKU",
    "description": "Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created",
    "metadata": {
      "assignedBy": "Cheapskate Boss"
    },
    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1",
    "definitionVersion": "1.*.*",
    "parameters": {
      "listOfAllowedSKUs": {
        "value": [
          "Standard_GRS",
          "Standard_LRS"
        ]
      }
    },
    "enforcementMode": "Default"
  }
}

範例回覆

{
  "properties": {
    "displayName": "Enforce storage account SKU",
    "description": "Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created",
    "metadata": {
      "assignedBy": "Cheapskate Boss"
    },
    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1",
    "definitionVersion": "1.*.*",
    "notScopes": [],
    "parameters": {
      "listOfAllowedSKUs": {
        "value": [
          "Standard_GRS",
          "Standard_LRS"
        ]
      }
    },
    "enforcementMode": "Default",
    "instanceId": "b7e0f8a9-1c2d-4e3f-8b4c-5d6e7f8a9b0c"
  },
  "id": "/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage",
  "type": "Microsoft.Authorization/policyAssignments",
  "name": "LowCostStorage"
}

Create or update policy assignment with a managed identity by ID

範例要求

PUT https://management.azure.com/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage?api-version=2025-01-01

{
  "identity": {
    "type": "SystemAssigned"
  },
  "location": "eastus",
  "properties": {
    "displayName": "Enforce storage account SKU",
    "description": "Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created",
    "metadata": {
      "assignedBy": "Cheapskate Boss"
    },
    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1",
    "definitionVersion": "1.*.*",
    "parameters": {
      "listOfAllowedSKUs": {
        "value": [
          "Standard_GRS",
          "Standard_LRS"
        ]
      }
    },
    "enforcementMode": "Default"
  }
}

範例回覆

{
  "properties": {
    "displayName": "Enforce storage account SKU",
    "description": "Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created",
    "metadata": {
      "assignedBy": "Cheapskate Boss"
    },
    "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1",
    "definitionVersion": "1.*.*",
    "notScopes": [],
    "parameters": {
      "listOfAllowedSKUs": {
        "value": [
          "Standard_GRS",
          "Standard_LRS"
        ]
      }
    },
    "enforcementMode": "Default",
    "instanceId": "b7e0f8a9-1c2d-4e3f-8b4c-5d6e7f8a9b0c"
  },
  "identity": {
    "type": "SystemAssigned",
    "principalId": "e6d23f8d-af97-4fbc-bda6-00604e4e3d0a",
    "tenantId": "4bee2b8a-1bee-47c2-90e9-404241551135"
  },
  "location": "eastus",
  "id": "/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage",
  "type": "Microsoft.Authorization/policyAssignments",
  "name": "LowCostStorage"
}

定義

名稱 Description
assignmentType

原則指派的類型。 可能的值為 NotSpecified、System、SystemHidden 和 Custom。 變。

CloudError

原則作業的錯誤回應。

createdByType

建立資源的身分識別類型。

enforcementMode

原則指派強制模式。 可能的值為 Default、DoNotEnforce 和 Enroll

ErrorAdditionalInfo

資源管理錯誤其他資訊。

ErrorResponse

錯誤回應

Identity

資源的身分識別。 政策指派最多支援一個身份。 這要麼是系統指定的身份,要麼是單一使用者指定的身份。

NonComplianceMessage

描述資源不符合原則之原因的訊息。 這會顯示在「拒絕」錯誤訊息和資源不符合規範的合規性結果中。

Override

原則屬性值覆寫。

OverrideKind

覆寫種類。

ParameterValuesValue

參數的值。

PolicyAssignment

政策分配。

ResourceIdentityType

識別類型。 將系統或使用者指派的身分識別新增至資源時,這是唯一的必要字段。

ResourceSelector

依資源屬性篩選原則的資源選取器。

Selector

選取器表達式。

SelectorKind

選取器種類。

systemData

與建立和上次修改資源相關的元數據。

UserAssignedIdentities

與原則相關聯的使用者身分識別。 使用者身分識別字典索引鍵參考的格式為 ARM 資源標識符:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'。

assignmentType

原則指派的類型。 可能的值為 NotSpecified、System、SystemHidden 和 Custom。 變。

Description
NotSpecified
System
SystemHidden
Custom

CloudError

原則作業的錯誤回應。

名稱 類型 Description
error

ErrorResponse

錯誤回應
所有 Azure Resource Manager API 的常見錯誤回應,用於回傳失敗操作的錯誤細節。 (這也遵循 OData 錯誤回應格式。)

createdByType

建立資源的身分識別類型。

Description
User
Application
ManagedIdentity
Key

enforcementMode

原則指派強制模式。 可能的值為 Default、DoNotEnforce 和 Enroll

Description
Default

原則效果會在資源建立或更新期間受到強制執行。

DoNotEnforce

在資源建立或更新時,政策效果不會被強制執行。

Enroll

在資源建立或更新時,政策效果不會強制執行,直到資源或資源的作用域被註冊到指派實例。 註冊發生於保單註冊資源部署時。

ErrorAdditionalInfo

資源管理錯誤其他資訊。

名稱 類型 Description
info

object

其他資訊。

type

string

其他信息類型。

ErrorResponse

錯誤回應

名稱 類型 Description
additionalInfo

ErrorAdditionalInfo[]

錯誤其他資訊。

code

string

錯誤碼。

details

ErrorResponse[]

錯誤詳情

message

string

錯誤訊息。

target

string

錯誤目標。

Identity

資源的身分識別。 政策指派最多支援一個身份。 這要麼是系統指定的身份,要麼是單一使用者指定的身份。

名稱 類型 Description
principalId

string

資源身份的主 ID。 此屬性僅適用於系統指派身份

tenantId

string

資源識別碼的租戶 ID。 此屬性僅適用於系統指派身份

type

ResourceIdentityType

識別類型。 將系統或使用者指派的身分識別新增至資源時,這是唯一的必要字段。

userAssignedIdentities

UserAssignedIdentities

與原則相關聯的使用者身分識別。 使用者身分識別字典索引鍵參考的格式為 ARM 資源標識符:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'。

NonComplianceMessage

描述資源不符合原則之原因的訊息。 這會顯示在「拒絕」錯誤訊息和資源不符合規範的合規性結果中。

名稱 類型 Description
message

string

描述資源不符合原則之原因的訊息。 這會顯示在「拒絕」錯誤訊息和資源不符合規範的合規性結果中。

policyDefinitionReferenceId

string

原則集合定義中訊息的目標原則定義參考標識符。 這隻適用於原則指派指派原則集定義時。 如果未提供此訊息,訊息會套用至此原則指派指派的所有原則。

Override

原則屬性值覆寫。

名稱 類型 Description
kind

OverrideKind

覆寫種類。

selectors

Selector[]

選取器表達式的清單。

value

string

要覆寫原則屬性的值。

OverrideKind

覆寫種類。

Description
policyEffect

它會覆蓋保單效應類型。

definitionVersion

它會覆寫政策指派的定義版本屬性值。

ParameterValuesValue

參數的值。

名稱 類型 Description
value

參數的值。

PolicyAssignment

政策分配。

名稱 類型 預設值 Description
id

string

原則指派的標識碼。

identity

Identity

與原則指派相關聯的受控識別。

location

string

原則指派的位置。 只有在使用受控識別時才需要。

name

string

原則指派的名稱。

properties.assignmentType

assignmentType

原則指派的類型。 可能的值為 NotSpecified、System、SystemHidden 和 Custom。 變。

properties.definitionVersion

string

要使用的原則定義版本。

properties.description

string

如果違反原則,此訊息將會是回應的一部分。

properties.displayName

string

原則指派的顯示名稱。

properties.effectiveDefinitionVersion

string

目前使用的政策定義的有效版本。 只有在透過 $expand 查詢參數請求時才會存在。

properties.enforcementMode

enforcementMode

Default

原則指派強制模式。 可能的值為 Default、DoNotEnforce 和 Enroll

properties.instanceId

string

政策指派的實例 ID。 這個 ID 只有在刪除並重新建立指派時才會改變。

properties.latestDefinitionVersion

string

最新版本的保單定義可供參考。 只有在透過 $expand 查詢參數請求時才會存在。

properties.metadata

object

原則指派元數據。 元數據是開放式物件,通常是索引鍵值組的集合。

properties.nonComplianceMessages

NonComplianceMessage[]

描述資源不符合原則之原因的訊息。

properties.notScopes

string[]

原則的排除範圍。

properties.overrides

Override[]

原則屬性值覆寫。

properties.parameters

<string,  ParameterValuesValue>

指派原則規則的參數值。 索引鍵是參數名稱。

properties.policyDefinitionId

string

要指派的原則定義或原則集定義的標識碼。

properties.resourceSelectors

ResourceSelector[]

依資源屬性篩選原則的資源選取器清單。

properties.scope

string

原則指派的範圍。

systemData

systemData

與此資源相關的系統元數據。

type

string

保單分配的類型。

ResourceIdentityType

識別類型。 將系統或使用者指派的身分識別新增至資源時,這是唯一的必要字段。

Description
SystemAssigned

表示該資源有系統指派的身份。

UserAssigned

表示該資源有系統指派的身份。

None

表示該資源沒有相關身份,或現有身份應被移除。

ResourceSelector

依資源屬性篩選原則的資源選取器。

名稱 類型 Description
name

string

資源選取器的名稱。

selectors

Selector[]

選取器表達式的清單。

Selector

選取器表達式。

名稱 類型 Description
in

string[]

要篩選的值清單。

kind

SelectorKind

選取器種類。

notIn

string[]

要篩選掉的值清單。

SelectorKind

選取器種類。

Description
resourceLocation

依資源位置篩選原則的選取器種類。

resourceType

依資源類型篩選原則的選取器種類。

resourceWithoutLocation

依沒有位置的資源篩選原則的選取器種類。

policyDefinitionReferenceId

依原則定義參考標識元篩選原則的選取器種類。

systemData

與建立和上次修改資源相關的元數據。

名稱 類型 Description
createdAt

string (date-time)

資源建立的時間戳(UTC)。

createdBy

string

建立資源的身分識別。

createdByType

createdByType

建立資源的身分識別類型。

lastModifiedAt

string (date-time)

上次修改的資源時間戳 (UTC)

lastModifiedBy

string

上次修改資源的身分識別。

lastModifiedByType

createdByType

上次修改資源的身分識別類型。

UserAssignedIdentities

與原則相關聯的使用者身分識別。 使用者身分識別字典索引鍵參考的格式為 ARM 資源標識符:'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'。

名稱 類型 Description