az policy definition
管理资源策略定义。
命令
名称 | 说明 | 类型 | Status |
---|---|---|---|
az policy definition create |
创建策略定义。 |
Core | GA |
az policy definition delete |
删除策略定义。 |
Core | Deprecated |
az policy definition list |
列出策略定义。 |
Core | GA |
az policy definition show |
显示策略定义。 |
Core | GA |
az policy definition update |
更新策略定义。 |
Core | GA |
az policy definition create
创建策略定义。
az policy definition create --name
[--description]
[--display-name]
[--management-group]
[--metadata]
[--mode]
[--params]
[--rules]
[--subscription]
示例
创建只读策略。
az policy definition create --name readOnlyStorage --rules "{ \"if\": \
{ \"field\": \"type\", \"equals\": \"Microsoft.Storage/storageAccounts/write\" }, \
\"then\": { \"effect\": \"deny\" } }"
创建策略参数定义。
az policy definition create --name allowedLocations \
--rules "{ \"if\": { \"allOf\": [ \
{ \"field\": \"location\",\"notIn\": \"[parameters('listOfAllowedLocations')]\" }, \
{ \"field\": \"location\", \"notEquals\": \"global\" }, \
{ \"field\": \"type\", \"notEquals\": \
\"Microsoft.AzureActiveDirectory/b2cDirectories\"} \
] }, \"then\": { \"effect\": \"deny\" } }" \
--params "{ \"allowedLocations\": { \
\"type\": \"array\", \"metadata\": { \"description\": \
\"The list of locations that can be specified when deploying resources\", \
\"strongType\": \"location\", \"displayName\": \"Allowed locations\" } } }"
创建可在管理组中应用的只读策略。
az policy definition create -n readOnlyStorage --management-group "MyManagementGroup" \
--rules "{ \"if\": { \"field\": \"type\", \
\"equals\": \"Microsoft.Storage/storageAccounts/write\" }, \
\"then\": { \"effect\": \"deny\" } }"
使用模式创建策略定义。 模式“Indexed”指示应仅针对支持标记和位置的资源类型评估策略。
az policy definition create --name TagsPolicyDefinition --subscription "MySubscription" \
--mode Indexed --rules "{ \"if\": { \"field\": \"tags\", \"exists\": \"false\" }, \
\"then\": { \"effect\": \"deny\" } }"
必需参数
新策略定义的名称。
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
策略定义的说明。
策略定义的显示名称。
可以在其中分配新策略定义的管理组的名称。
空格分隔键值对中的元数据。
策略定义的模式,例如所有索引。 有关详细信息,请访问 https://aka.ms/azure-policy-mode。
JSON 格式的字符串或包含参数定义的文件或 URI 的路径。
JSON 格式的策略规则,或包含 JSON 规则的文件的路径。
可以在其中分配新策略定义的订阅的名称或 ID。
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
Output format.
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az policy definition delete
资源命令的未来版本中的行为将发生变化。 绕过确认提示需要提供 -y 开关。
删除策略定义。
az policy definition delete --name
[--management-group]
[--subscription]
示例
删除策略定义。 (autogenerated)
az policy definition delete --name MyPolicyDefinition
必需参数
策略定义名称。
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
策略 [set] 定义的管理组的名称。 如果策略集的范围限定为管理组,则此参数是必需的。
策略 [set] 定义的订阅 ID。
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
Output format.
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az policy definition list
列出策略定义。
az policy definition list [--management-group]
[--subscription]
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
策略 [set] 定义的管理组的名称。 如果策略集的范围限定为管理组,则此参数是必需的。
策略 [set] 定义的订阅 ID。
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
Output format.
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az policy definition show
显示策略定义。
az policy definition show --name
[--management-group]
[--subscription]
示例
显示策略定义。 (autogenerated)
az policy definition show --name MyPolicyDefinition
必需参数
策略定义名称。
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
策略 [set] 定义的管理组的名称。 如果策略集的范围限定为管理组,则此参数是必需的。
策略 [set] 定义的订阅 ID。
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
Output format.
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |
az policy definition update
更新策略定义。
az policy definition update --name
[--description]
[--display-name]
[--management-group]
[--metadata]
[--mode]
[--params]
[--rules]
[--subscription]
示例
更新策略定义。 (autogenerated)
az policy definition update --name MyPolicyDefinition
必需参数
策略定义名称。
可选参数
The following parameters are optional, but depending on the context, one or more might become required for the command to execute successfully.
策略定义的说明。
策略定义的显示名称。
策略 [set] 定义的管理组的名称。 如果策略集的范围限定为管理组,则此参数是必需的。
空格分隔键值对中的元数据。
策略定义的模式,例如所有索引。 有关详细信息,请访问 https://aka.ms/azure-policy-mode。
JSON 格式的字符串或包含参数定义的文件或 URI 的路径。
JSON 格式的字符串或包含此类内容的文件的路径。
策略 [set] 定义的订阅 ID。
全局参数
提高日志记录详细程度以显示所有调试日志。
属性 | 值 |
---|---|
默认值: | False |
显示此帮助消息并退出。
仅显示错误,禁止显示警告。
属性 | 值 |
---|---|
默认值: | False |
Output format.
属性 | 值 |
---|---|
默认值: | json |
接受的值: | json, jsonc, none, table, tsv, yaml, yamlc |
JMESPath 查询字符串。 有关更多信息和示例,请参阅 http://jmespath.org/。
增加日志记录详细程度。 使用 --debug 获取完整的调试日志。
属性 | 值 |
---|---|
默认值: | False |