次の方法で共有


Policy Definitions - Create Or Update

この操作は、与えられたサブスクリプション内で名前のポリシー定義を作成または更新します。

PUT https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}?api-version=2025-11-01

URI パラメーター

名前 / 必須 説明
policyDefinitionName
path True

string

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

取得するポリシー定義の名前。

subscriptionId
path True

string (uuid)

ターゲット サブスクリプションの ID。 値は UUID である必要があります。

api-version
query True

string

minLength: 1

この操作に使用する API バージョン。

要求本文

名前 説明
properties.description

string

ポリシー定義の説明。

properties.displayName

string

ポリシー定義の表示名。

properties.externalEvaluationEnforcementSettings

ExternalEvaluationEnforcementSettings

適用の評価中にポリシーに必要な外部評価結果のソースの詳細。

properties.metadata

ポリシー定義メタデータ。 メタデータはオープン エンド オブジェクトであり、通常はキーと値のペアのコレクションです。

properties.mode

string

ポリシー定義モード。 たとえば、All、Indexed、Microsoft.KeyVault.Data などです。

properties.parameters

<string,  ParameterDefinitionsValue>

ポリシー規則で使用されるパラメーターのパラメーター定義。 キーはパラメーター名です。

properties.policyRule

ポリシー ルール。

properties.policyType

PolicyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

properties.version

string

#.#.# 形式のポリシー定義のバージョン。

properties.versions

string[]

このポリシー定義で使用可能なバージョンの一覧。

応答

名前 説明
201 Created

PolicyDefinition

リソース「PolicyDefinition」作成操作が成功しました

Other Status Codes

ErrorResponse

予期しないエラー応答。

セキュリティ

azure_auth

Azure Active Directory OAuth2 Flow.

型: oauth2
フロー: implicit
Authorization URL (承認 URL): https://login.microsoftonline.com/common/oauth2/authorize

スコープ

名前 説明
user_impersonation ユーザー アカウントを偽装する

Create or update a policy definition
Create or update a policy definition with advanced parameters
Create or update a policy definition with external evaluation enforcement settings

Create or update a policy definition

要求のサンプル

PUT https://management.azure.com/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming?api-version=2025-11-01

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

応答のサンプル

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

Create or update a policy definition with advanced parameters

要求のサンプル

PUT https://management.azure.com/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/EventHubDiagnosticLogs?api-version=2025-11-01

{
  "properties": {
    "description": "Audit enabling of logs and retain them up to a year. This enables recreation of activity trails for investigation purposes when a security incident occurs or your network is compromised",
    "displayName": "Event Hubs should have diagnostic logging enabled",
    "metadata": {
      "category": "Event Hub"
    },
    "mode": "Indexed",
    "parameters": {
      "requiredRetentionDays": {
        "type": "Integer",
        "allowedValues": [
          0,
          30,
          90,
          180,
          365
        ],
        "defaultValue": 365,
        "metadata": {
          "description": "The required diagnostic logs retention in days",
          "displayName": "Required retention (days)"
        }
      }
    },
    "policyRule": {
      "if": {
        "equals": "Microsoft.EventHub/namespaces",
        "field": "type"
      },
      "then": {
        "effect": "AuditIfNotExists",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "existenceCondition": {
            "allOf": [
              {
                "equals": "true",
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled"
              },
              {
                "equals": "[parameters('requiredRetentionDays')]",
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days"
              }
            ]
          }
        }
      }
    }
  }
}

応答のサンプル

{
  "name": "ResourceNaming",
  "type": "Microsoft.Authorization/policyDefinitions",
  "id": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming",
  "properties": {
    "description": "Audit enabling of logs and retain them up to a year. This enables recreation of activity trails for investigation purposes when a security incident occurs or your network is compromised",
    "displayName": "Event Hubs should have diagnostic logging enabled",
    "metadata": {
      "category": "Event Hub"
    },
    "mode": "Indexed",
    "parameters": {
      "requiredRetentionDays": {
        "type": "Integer",
        "allowedValues": [
          0,
          30,
          90,
          180,
          365
        ],
        "defaultValue": 365,
        "metadata": {
          "description": "The required diagnostic logs retention in days",
          "displayName": "Required retention (days)"
        }
      }
    },
    "policyRule": {
      "if": {
        "equals": "Microsoft.EventHub/namespaces",
        "field": "type"
      },
      "then": {
        "effect": "AuditIfNotExists",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "existenceCondition": {
            "allOf": [
              {
                "equals": "true",
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled"
              },
              {
                "equals": "[parameters('requiredRetentionDays')]",
                "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days"
              }
            ]
          }
        }
      }
    },
    "version": "1.2.1",
    "versions": [
      "1.2.1",
      "1.0.0"
    ]
  }
}

Create or update a policy definition with external evaluation enforcement settings

要求のサンプル

PUT https://management.azure.com/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/RandomizeVMAllocation?api-version=2025-11-01

{
  "properties": {
    "description": "Randomly disable VM allocation in eastus by having policy rule reference the outcome of invoking an external endpoint using the CoinFlip endpoint that returns random values.",
    "displayName": "Randomize VM Allocation",
    "externalEvaluationEnforcementSettings": {
      "endpointSettings": {
        "kind": "CoinFlip",
        "details": {
          "successProbability": 0.5
        }
      },
      "missingTokenAction": "audit",
      "roleDefinitionIds": [
        "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/roleDefinitions/f0cc2aea-b517-48f6-8f9e-0c01c687907b"
      ]
    },
    "metadata": {
      "category": "VM"
    },
    "mode": "Indexed",
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.Compute/virtualMachines",
            "field": "type"
          },
          {
            "equals": "eastus",
            "field": "location"
          },
          {
            "equals": "false",
            "value": "[claims().isValid]"
          }
        ]
      },
      "then": {
        "effect": "deny"
      }
    }
  }
}

応答のサンプル

{
  "name": "RandomizeVMAllocation",
  "type": "Microsoft.Authorization/policyDefinitions",
  "id": "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/RandomizeVMAllocation",
  "properties": {
    "description": "Randomly disable VM allocation in eastus by having policy rule reference the outcome of invoking an external endpoint using the CoinFlip endpoint that returns random values.",
    "displayName": "Randomize VM Allocation",
    "externalEvaluationEnforcementSettings": {
      "endpointSettings": {
        "kind": "CoinFlip",
        "details": {
          "successProbability": 0.5
        }
      },
      "missingTokenAction": "audit",
      "roleDefinitionIds": [
        "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/roleDefinitions/f0cc2aea-b517-48f6-8f9e-0c01c687907b"
      ]
    },
    "metadata": {
      "category": "VM"
    },
    "mode": "Indexed",
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.Compute/virtualMachines",
            "field": "type"
          },
          {
            "equals": "eastus",
            "field": "location"
          },
          {
            "equals": "false",
            "value": "[claims().isValid]"
          }
        ]
      },
      "then": {
        "effect": "deny"
      }
    },
    "policyType": "Custom",
    "version": "1.2.1",
    "versions": [
      "1.2.1",
      "1.0.0"
    ]
  }
}

定義

名前 説明
createdByType

リソースを作成した ID の種類。

ErrorAdditionalInfo

リソース管理エラーの追加情報。

ErrorDetail

エラーの詳細。

ErrorResponse

エラー応答

ExternalEvaluationEndpointSettings

評価結果を提供する外部エンドポイントの設定。

ExternalEvaluationEnforcementSettings

適用の評価中にポリシーに必要な外部評価結果のソースの詳細。

ParameterDefinitionsValue

ポリシーに提供できるパラメータの定義。

ParameterDefinitionsValueMetadata

パラメーターの一般的なメタデータ。

ParameterType

パラメーターのデータ型。

PolicyDefinition

政策の定義。

PolicyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

systemData

リソースの作成と最後の変更に関連するメタデータ。

createdByType

リソースを作成した ID の種類。

説明
User
Application
ManagedIdentity
Key

ErrorAdditionalInfo

リソース管理エラーの追加情報。

名前 説明
info

object

追加情報。

type

string

追加情報の種類。

ErrorDetail

エラーの詳細。

名前 説明
additionalInfo

ErrorAdditionalInfo[]

エラーの追加情報。

code

string

エラー コード。

details

ErrorDetail[]

エラーの詳細。

message

string

エラー メッセージ。

target

string

エラーターゲット。

ErrorResponse

エラー応答

名前 説明
error

ErrorDetail

エラー オブジェクト。

ExternalEvaluationEndpointSettings

評価結果を提供する外部エンドポイントの設定。

名前 説明
details

エンドポイントの詳細。

kind

string

エンドポイントの種類。

ExternalEvaluationEnforcementSettings

適用の評価中にポリシーに必要な外部評価結果のソースの詳細。

名前 説明
endpointSettings

ExternalEvaluationEndpointSettings

評価結果を提供する外部エンドポイントの設定。

missingTokenAction

string

外部評価を必要とし、トークンが不足している適用ポリシーを評価する場合の処理。 使用可能な値は Audit と Deny であり、言語式がサポートされています。

resultLifespan

string

エンドポイント呼び出しの結果の有効期間。その後、有効ではなくなります。 値は ISO 8601 期間形式に従う必要があり、言語式がサポートされています。

roleDefinitionIds

string[]

エンドポイントを呼び出すために割り当ての MSI が必要とするロール定義 ID の配列。

ParameterDefinitionsValue

ポリシーに提供できるパラメータの定義。

名前 説明
allowedValues

AllowedValues[]

パラメーターに使用できる値。

defaultValue

値が指定されていない場合のパラメーターの既定値。

metadata

ParameterDefinitionsValueMetadata

パラメーターの一般的なメタデータ。

schema

自己定義 JSON スキーマを使用した割り当て時のパラメーター入力の検証を提供します。 このプロパティはオブジェクト型パラメータのみをサポートし、Json.NET Schema 2019-09の実装に従っています。 スキーマの使い方についてはhttps://json-schema.org/で、ドラフトスキーマのテストについてはhttps://www.jsonschemavalidator.net/で学べます。

type

ParameterType

パラメーターのデータ型。

ParameterDefinitionsValueMetadata

パラメーターの一般的なメタデータ。

名前 説明
assignPermissions

boolean

ポリシー割り当て時に、AzureポータルがこのパラメータのリソースIDまたはリソーススコープ値に対してロール割り当てを作成するためにtrueに設定してください。 このプロパティは、割り当てスコープ外でアクセス許可を割り当てる場合に便利です。

description

string

パラメーターの説明。

displayName

string

パラメーターの表示名。

strongType

string

ポータルを使用してポリシー定義を割り当てるときに使用されます。 ユーザーが選択する値のコンテキスト対応リストを提供します。

ParameterType

パラメーターのデータ型。

説明
String

文字列パラメータタイプです。

Array

配列パラメータ型。

Object

オブジェクトパラメータタイプです。

Boolean

ブールパラメータ型。

Integer

整数パラメータ型です。

Float

floatパラメータ型です。

DateTime

日付-時刻パラメータ型です。

PolicyDefinition

政策の定義。

名前 規定値 説明
id

string (arm-id)

リソースの完全修飾リソース ID。 例: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}"

name

string

リソースの名前

properties.description

string

ポリシー定義の説明。

properties.displayName

string

ポリシー定義の表示名。

properties.externalEvaluationEnforcementSettings

ExternalEvaluationEnforcementSettings

適用の評価中にポリシーに必要な外部評価結果のソースの詳細。

properties.metadata

ポリシー定義メタデータ。 メタデータはオープン エンド オブジェクトであり、通常はキーと値のペアのコレクションです。

properties.mode

string

Indexed

ポリシー定義モード。 たとえば、All、Indexed、Microsoft.KeyVault.Data などです。

properties.parameters

<string,  ParameterDefinitionsValue>

ポリシー規則で使用されるパラメーターのパラメーター定義。 キーはパラメーター名です。

properties.policyRule

ポリシー ルール。

properties.policyType

PolicyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

properties.version

string

#.#.# 形式のポリシー定義のバージョン。

properties.versions

string[]

このポリシー定義で使用可能なバージョンの一覧。

systemData

systemData

create By と modifiedBy の情報を含む Azure Resource Manager メタデータ。

type

string

リソースの型。 例: "Microsoft.Compute/virtualMachines" または "Microsoft.Storage/storageAccounts"

PolicyType

ポリシー定義の種類。 指定できる値は、NotSpecified、BuiltIn、Custom、Static です。

説明
NotSpecified

未指定のポリシー定義タイプ。

BuiltIn

組み込みのポリシー定義タイプ。

Custom

カスタムポリシー定義タイプ。

Static

静的ポリシー定義タイプ。

systemData

リソースの作成と最後の変更に関連するメタデータ。

名前 説明
createdAt

string (date-time)

リソース作成のタイムスタンプ (UTC)。

createdBy

string

リソースを作成した ID。

createdByType

createdByType

リソースを作成した ID の種類。

lastModifiedAt

string (date-time)

リソースの最終変更のタイムスタンプ (UTC)

lastModifiedBy

string

リソースを最後に変更した ID。

lastModifiedByType

createdByType

リソースを最後に変更した ID の種類。