你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
如何使用 Bicep 创建计算机配置分配
可以使用 Azure Bicep 来部署计算机配置分配。 本文演示了部署自定义配置和内置配置的示例。
在以下每个部分,示例都包含一个名称以 Microsoft.Compute/virtualMachines
开头的类型属性。 来宾配置资源提供程序 Microsoft.GuestConfiguration
是必须引用父类型的扩展资源。
若要修改示例以适用于其他资源类型(例如已启用 Arc 的服务器),可将父类型更改为资源提供程序的名称。 对于已启用 Arc 的服务器,资源提供程序为 Microsoft.HybridCompute/machines
。
将以下“<>”字段替换为特定于你的环境的值:
<vm_name>
:指定要应用配置的计算机资源的名称。<configuration_name>
:指定要应用的配置的名称。<vm_location>
:指定要用于创建机器配置分配的 Azure 区域。<Url_to_Package.zip>
:指定自定义内容包.zip
文件的 HTTPS 链接。<SHA256_hash_of_package.zip>
:指定自定义内容包.zip
文件的 SHA256 哈希。
分配自定义配置
以下示例分配自定义配置。
resource myVM 'Microsoft.Compute/virtualMachines@2021-03-01' existing = {
name: '<vm_name>'
}
resource myConfiguration 'Microsoft.GuestConfiguration/guestConfigurationAssignments@2020-06-25' = {
name: '<configuration_name>'
scope: myVM
location: resourceGroup().location
properties: {
guestConfiguration: {
name: '<configuration_name>'
contentUri: '<Url_to_Package.zip>'
contentHash: '<SHA256_hash_of_package.zip>'
version: '1.*'
assignmentType: 'ApplyAndMonitor'
}
}
}
分配内置配置
以下示例分配 AzureWindowBaseline
内置配置。
resource myWindowsVM 'Microsoft.Compute/virtualMachines@2021-03-01' existing = {
name: '<vm_name>'
}
resource AzureWindowsBaseline 'Microsoft.GuestConfiguration/guestConfigurationAssignments@2020-06-25' = {
name: 'AzureWindowsBaseline'
scope: myWindowsVM
location: resourceGroup().location
properties: {
guestConfiguration: {
name: 'AzureWindowsBaseline'
version: '1.*'
assignmentType: 'ApplyAndMonitor'
configurationParameter: [
{
name: 'Minimum Password Length;ExpectedValue'
value: '16'
}
{
name: 'Minimum Password Length;RemediateValue'
value: '16'
}
{
name: 'Maximum Password Age;ExpectedValue'
value: '75'
}
{
name: 'Maximum Password Age;RemediateValue'
value: '75'
}
]
}
}
}