你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Microsoft.VirtualMachineImages imageTemplates

Bicep 资源定义

imageTemplates 资源类型可以部署到:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.VirtualMachineImages/imageTemplates 资源,请将以下 Bicep 添加到模板。

resource symbolicname 'Microsoft.VirtualMachineImages/imageTemplates@2022-02-14' = {
  name: 'string'
  location: 'string'
  tags: {
    tagName1: 'tagValue1'
    tagName2: 'tagValue2'
  }
  identity: {
    type: 'string'
    userAssignedIdentities: {}
  }
  properties: {
    buildTimeoutInMinutes: int
    customize: [
      {
        name: 'string'
        type: 'string'
        // For remaining properties, see ImageTemplateCustomizer objects
      }
    ]
    distribute: [
      {
        artifactTags: {}
        runOutputName: 'string'
        type: 'string'
        // For remaining properties, see ImageTemplateDistributor objects
      }
    ]
    source: {
      type: 'string'
      // For remaining properties, see ImageTemplateSource objects
    }
    stagingResourceGroup: 'string'
    validate: {
      continueDistributeOnFailure: bool
      inVMValidations: [
        {
          name: 'string'
          type: 'string'
          // For remaining properties, see ImageTemplateInVMValidator objects
        }
      ]
      sourceValidationOnly: bool
    }
    vmProfile: {
      osDiskSizeGB: int
      userAssignedIdentities: [
        'string'
      ]
      vmSize: 'string'
      vnetConfig: {
        proxyVmSize: 'string'
        subnetId: 'string'
      }
    }
  }
}

ImageTemplateCustomizer 对象

设置 type 属性以指定对象的类型。

对于 “文件”,请使用:

  type: 'File'
  destination: 'string'
  sha256Checksum: 'string'
  sourceUri: 'string'

对于 PowerShell,请使用:

  type: 'PowerShell'
  inline: [
    'string'
  ]
  runAsSystem: bool
  runElevated: bool
  scriptUri: 'string'
  sha256Checksum: 'string'
  validExitCodes: [
    int
  ]

对于 Shell,请使用:

  type: 'Shell'
  inline: [
    'string'
  ]
  scriptUri: 'string'
  sha256Checksum: 'string'

对于 WindowsRestart,请使用:

  type: 'WindowsRestart'
  restartCheckCommand: 'string'
  restartCommand: 'string'
  restartTimeout: 'string'

对于 WindowsUpdate,请使用:

  type: 'WindowsUpdate'
  filters: [
    'string'
  ]
  searchCriteria: 'string'
  updateLimit: int

ImageTemplateDistributor 对象

设置 type 属性以指定对象的类型。

对于 ManagedImage,请使用:

  type: 'ManagedImage'
  imageId: 'string'
  location: 'string'

对于 SharedImage,请使用:

  type: 'SharedImage'
  excludeFromLatest: bool
  galleryImageId: 'string'
  replicationRegions: [
    'string'
  ]
  storageAccountType: 'string'

对于 VHD,请使用:

  type: 'VHD'

ImageTemplateSource 对象

设置 type 属性以指定对象的类型。

对于 ManagedImage,请使用:

  type: 'ManagedImage'
  imageId: 'string'

对于 PlatformImage,请使用:

  type: 'PlatformImage'
  offer: 'string'
  planInfo: {
    planName: 'string'
    planProduct: 'string'
    planPublisher: 'string'
  }
  publisher: 'string'
  sku: 'string'
  version: 'string'

对于 SharedImageVersion,请使用:

  type: 'SharedImageVersion'
  imageVersionId: 'string'

ImageTemplateInVMValidator 对象

设置 type 属性以指定对象的类型。

对于 PowerShell,请使用:

  type: 'PowerShell'
  inline: [
    'string'
  ]
  runAsSystem: bool
  runElevated: bool
  scriptUri: 'string'
  sha256Checksum: 'string'
  validExitCodes: [
    int
  ]

对于 Shell,请使用:

  type: 'Shell'
  inline: [
    'string'
  ]
  scriptUri: 'string'
  sha256Checksum: 'string'

属性值

imageTemplates

名称 说明
name 资源名称 字符串 (必需)
location 资源所在的地理位置 字符串 (必需)
标记 资源标记。 标记名称和值的字典。 请参阅 模板中的标记
标识 映像模板的标识(如果已配置)。 需要 ImageTemplateIdentity ()
properties 映像模板的属性 ImageTemplateProperties

ImageTemplateIdentity

名称 说明 Value
type 用于映像模板的标识类型。 类型“None”将从映像模板中删除任何标识。 “None”
“UserAssigned”
userAssignedIdentities 与映像模板关联的用户标识列表。 用户标识字典键引用将是 ARM 资源 ID,格式为:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 对象 (object)

ImageTemplateProperties

名称 说明
buildTimeoutInMinutes 生成映像模板时等待的最长持续时间(包括所有自定义、验证和分发)。 省略或指定 0 以使用默认 (4 小时) 。 int
自定义 指定用于描述映像的自定义步骤的属性,如图像源等 ImageTemplateCustomizer[]
分发 (distribute) 映像输出需要转到的分发目标。 ImageTemplateDistributor[] (必需)
source 指定用于描述源图像的属性。 ImageTemplateSource (必需)
stagingResourceGroup 将用于生成映像的映像模板所在的订阅中的暂存资源组 ID。 如果此字段为空,则将创建具有随机名称的资源组。 如果此字段中指定的资源组不存在,则将使用相同的名称创建该资源组。 如果指定的资源组存在,则它必须为空,并且与映像模板位于同一区域中。 如果此字段为空或指定的资源组不存在,则在模板删除期间将删除创建的资源组,但如果指定的资源组存在,则在删除模板期间将删除在资源组中创建的资源,并且资源组本身将保留。 string
validate 要对生成的映像执行的配置选项和验证列表。 ImageTemplatePropertiesValidate
vmProfile 介绍如何设置虚拟机以生成映像 ImageTemplateVmProfile

ImageTemplateCustomizer

名称 说明
name 友好名称,用于提供有关此自定义步骤的上下文 string
type 设置对象类型 File
PowerShell
Shell
WindowsRestart
WindowsUpdate (必需)

ImageTemplateFileCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “File” (必需)
destination 文件 (的绝对路径,其中包含已创建的嵌套目录结构,) 将从 sourceUri) 中 (的文件上传到 VM 中 字符串
sha256Checksum 上述 sourceUri 字段中提供的文件的 SHA256 校验和 字符串
sourceUri 要上传用于自定义 VM 的文件的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 string

ImageTemplatePowerShellCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “PowerShell” (必需)
inline 要执行的 PowerShell 命令数组 string[]
runAsSystem 如果指定,将使用本地系统用户以提升的权限运行 PowerShell 脚本。 仅当上面的 runElevated 字段设置为 true 时,才能为 true。 bool
runElevated 如果指定,则 PowerShell 脚本将使用提升的权限运行 bool
scriptUri 要运行用于自定义的 PowerShell 脚本的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 字符串
sha256Checksum 上面的 scriptUri 字段中提供的 power shell 脚本的 SHA256 校验和 字符串
validExitCodes PowerShell 脚本的有效退出代码。 [默认值:0] int[]

ImageTemplateShellCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “Shell” (必需)
inline 要执行的 shell 命令数组 string[]
scriptUri 要运行用于自定义的 shell 脚本的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 string
sha256Checksum scriptUri 字段中提供的 shell 脚本的 SHA256 校验和 字符串

ImageTemplateRestartCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “WindowsRestart” (必需)
restartCheckCommand 重启成功时检查的命令 [默认值: ''] 字符串
restartCommand 用于执行重启的命令 [默认值:'shutdown /r /f /t 0 /c “packer restart”'] 字符串
restartTimeout 重启超时指定为数量级和单位字符串,例如“5m” (5 分钟) 或“2h” (2 小时) [默认值:'5m'] 字符串

ImageTemplateWindowsUpdateCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “WindowsUpdate” (必需)
筛选器 要选择要应用的更新的筛选器数组。 省略或指定空数组以使用默认 (无筛选器) 。 有关此字段的示例和详细说明,请参阅上面的链接。 string[]
searchCriteria 搜索更新的条件。 省略或指定空字符串以使用默认 (搜索所有) 。 有关此字段的示例和详细说明,请参阅上面的链接。 string
updateLimit 一次应用的最大更新数。 省略或指定 0 以使用默认 (1000) int

ImageTemplateDistributor

名称 说明
artifactTags 分发服务器创建/更新项目后将应用于项目的标记。 对象 (object)
runOutputName 要用于关联的 RunOutput 的名称。 字符串 (必需)
类型 设置对象类型 ManagedImage
SharedImage
需要 VHD ()

ImageTemplateManagedImageDistributor

名称 说明 Value
type 分发类型。 需要“ManagedImage” ()
imageId 托管磁盘映像的资源 ID 字符串 (必需)
location 映像的 Azure 位置(如果映像已存在)应匹配 字符串 (必需)

ImageTemplateSharedImageDistributor

名称 说明 Value
type 分发类型。 需要“SharedImage” ()
excludeFromLatest 指示是否应从最新映像中排除创建的映像版本的标志。 省略以使用默认 (false) 。 bool
galleryImageId 共享映像库映像的资源 ID 字符串 (必需)
replicationRegions 映像将复制到的区域列表 string[] (必需)
storageAccountType 用于存储共享映像的存储帐户类型。 省略 以使用默认 (Standard_LRS) 。 “Standard_LRS”
“Standard_ZRS”

ImageTemplateVhdDistributor

名称 说明 Value
type 分发类型。 “VHD” (必需)

ImageTemplateSource

名称 说明 Value
type 设置对象类型 ManagedImage
PlatformImage
需要 SharedImageVersion ()

ImageTemplateManagedImageSource

名称 说明 Value
type 指定要开始使用的源映像的类型。 需要“ManagedImage” ()
imageId 客户订阅中托管映像的 ARM 资源 ID 字符串 (必需)

ImageTemplatePlatformImageSource

名称 说明 Value
type 指定要从头开始使用的源图像的类型。 “PlatformImage” (必需)
offer Azure 库映像中的映像套餐。 字符串
planInfo 平台映像的购买计划的可选配置。 PlatformImagePurchasePlan
发布者 Azure 库映像中的映像发布服务器。 字符串
sku Azure 库映像中的映像 SKU。 字符串
版本 Azure 库映像中的映像版本。 如果此处指定了“latest”,则会在生成映像时评估版本,而不是在提交模板时评估版本。 string

PlatformImagePurchasePlan

名称 说明
planName 购买计划的名称。 字符串 (必需)
planProduct 购买计划的产品。 字符串 (必需)
planPublisher 购买计划的发布者。 字符串 (必需)

ImageTemplateSharedImageVersionSource

名称 说明 Value
type 指定要从头开始使用的源图像的类型。 需要“SharedImageVersion” ()
imageVersionId 共享映像库中映像版本的 ARM 资源 ID 字符串 (必需)

ImageTemplatePropertiesValidate

名称 说明
continueDistributeOnFailure 如果验证失败,并且此字段设置为 false,则不会分发输出映像 () 。 这是默认行为。 如果验证失败且此字段设置为 true,则仍会分发输出映像 () 。 请谨慎使用此选项,因为这可能会导致分发错误的映像以供使用。 在 (true 或 false) 的任一情况下,在验证失败时,端到端映像运行都将报告为失败。 [注意:如果验证成功,则此字段无效。] bool
inVMValidations 要执行的验证列表。 ImageTemplateInVMValidator[]
sourceValidationOnly 如果此字段设置为 true,将直接验证在“source”节中指定的图像。 不会运行单独的构建来生成,然后验证自定义映像。 bool

ImageTemplateInVMValidator

名称 说明
name 友好名称,用于提供有关此验证步骤的上下文 string
type 设置对象类型 PowerShell
需要 shell ()

ImageTemplatePowerShellValidator

名称 说明 Value
type 要对映像使用的验证类型。 例如,“Shell”可以是 shell 验证 “PowerShell” (必需)
inline 要执行的 PowerShell 命令数组 string[]
runAsSystem 如果指定,将使用本地系统用户以提升的权限运行 PowerShell 脚本。 仅当上面的 runElevated 字段设置为 true 时,才能为 true。 bool
runElevated 如果指定,则 PowerShell 脚本将使用提升的权限运行 bool
scriptUri 要运行用于验证的 PowerShell 脚本的 URI。 它可以是 github 链接、Azure 存储 URI 等 string
sha256Checksum 上面的 scriptUri 字段中提供的 power shell 脚本的 SHA256 校验和 字符串
validExitCodes PowerShell 脚本的有效退出代码。 [默认值:0] int[]

ImageTemplateShellValidator

名称 说明 Value
type 要对映像使用的验证类型。 例如,“Shell”可以是 shell 验证 “Shell” (必需)
inline 要执行的 shell 命令数组 string[]
scriptUri 要运行用于验证的 shell 脚本的 URI。 它可以是 github 链接、Azure 存储 URI 等 字符串
sha256Checksum scriptUri 字段中提供的 shell 脚本的 SHA256 校验和 字符串

ImageTemplateVmProfile

名称 说明
osDiskSizeGB OS 磁盘的大小(以 GB 为单位)。 省略或指定 0 以使用 Azure 的默认 OS 磁盘大小。 int
userAssignedIdentities 在生成 VM 和验证 VM 上配置的用户分配的托管标识的资源 ID 的可选数组。 这可能包括映像模板的标识。 string[]
vmSize 用于生成、自定义和捕获映像的虚拟机的大小。 省略或指定空字符串,以使用 Gen1 映像的默认 (Standard_D1_v2,Standard_D2ds_v4第 2 代映像) 。 string
vnetConfig 用于部署生成 VM 和验证 VM 的虚拟网络的可选配置。 如果不需要使用任何特定虚拟网络,则可将其省略。 VirtualNetworkConfig

VirtualNetworkConfig

名称 说明
proxyVmSize 用于将流量传递到生成 VM 和验证 VM 的代理虚拟机的大小。 省略或指定空字符串以使用默认 (Standard_A1_v2) 。 string
subnetId 预先存在的子网的资源 ID。 字符串

快速入门模板

以下快速入门模板部署此资源类型。

模板 说明
使用 Azure Windows 基线的 Azure 映像生成器

部署到 Azure
创建 Azure 映像生成器环境并生成应用了最新 Windows 汇报和 Azure Windows 基线的 Windows Server 映像。
配置 Dev Box 服务

部署到 Azure
此模板将按照 Dev Box 快速入门指南创建所有 Dev Box 管理员资源。 可以查看创建的所有资源,也可以直接转到 DevPortal.microsoft.com 创建第一个 Dev Box。

ARM 模板资源定义

imageTemplates 资源类型可以部署到:

有关每个 API 版本中更改的属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.VirtualMachineImages/imageTemplates 资源,请将以下 JSON 添加到模板。

{
  "type": "Microsoft.VirtualMachineImages/imageTemplates",
  "apiVersion": "2022-02-14",
  "name": "string",
  "location": "string",
  "tags": {
    "tagName1": "tagValue1",
    "tagName2": "tagValue2"
  },
  "identity": {
    "type": "string",
    "userAssignedIdentities": {}
  },
  "properties": {
    "buildTimeoutInMinutes": "int",
    "customize": [
      {
        "name": "string",
        "type": "string"
        // For remaining properties, see ImageTemplateCustomizer objects
      }
    ],
    "distribute": [
      {
        "artifactTags": {},
        "runOutputName": "string",
        "type": "string"
        // For remaining properties, see ImageTemplateDistributor objects
      }
    ],
    "source": {
      "type": "string"
      // For remaining properties, see ImageTemplateSource objects
    },
    "stagingResourceGroup": "string",
    "validate": {
      "continueDistributeOnFailure": "bool",
      "inVMValidations": [
        {
          "name": "string",
          "type": "string"
          // For remaining properties, see ImageTemplateInVMValidator objects
        }
      ],
      "sourceValidationOnly": "bool"
    },
    "vmProfile": {
      "osDiskSizeGB": "int",
      "userAssignedIdentities": [ "string" ],
      "vmSize": "string",
      "vnetConfig": {
        "proxyVmSize": "string",
        "subnetId": "string"
      }
    }
  }
}

ImageTemplateCustomizer 对象

设置 type 属性以指定对象的类型。

对于 “文件”,请使用:

  "type": "File",
  "destination": "string",
  "sha256Checksum": "string",
  "sourceUri": "string"

对于 PowerShell,请使用:

  "type": "PowerShell",
  "inline": [ "string" ],
  "runAsSystem": "bool",
  "runElevated": "bool",
  "scriptUri": "string",
  "sha256Checksum": "string",
  "validExitCodes": [ "int" ]

对于 Shell,请使用:

  "type": "Shell",
  "inline": [ "string" ],
  "scriptUri": "string",
  "sha256Checksum": "string"

对于 WindowsRestart,请使用:

  "type": "WindowsRestart",
  "restartCheckCommand": "string",
  "restartCommand": "string",
  "restartTimeout": "string"

对于 WindowsUpdate,请使用:

  "type": "WindowsUpdate",
  "filters": [ "string" ],
  "searchCriteria": "string",
  "updateLimit": "int"

ImageTemplateDistributor 对象

设置 type 属性以指定对象的类型。

对于 ManagedImage,请使用:

  "type": "ManagedImage",
  "imageId": "string",
  "location": "string"

对于 SharedImage,请使用:

  "type": "SharedImage",
  "excludeFromLatest": "bool",
  "galleryImageId": "string",
  "replicationRegions": [ "string" ],
  "storageAccountType": "string"

对于 VHD,请使用:

  "type": "VHD"

ImageTemplateSource 对象

设置 type 属性以指定对象的类型。

对于 ManagedImage,请使用:

  "type": "ManagedImage",
  "imageId": "string"

对于 PlatformImage,请使用:

  "type": "PlatformImage",
  "offer": "string",
  "planInfo": {
    "planName": "string",
    "planProduct": "string",
    "planPublisher": "string"
  },
  "publisher": "string",
  "sku": "string",
  "version": "string"

对于 SharedImageVersion,请使用:

  "type": "SharedImageVersion",
  "imageVersionId": "string"

ImageTemplateInVMValidator 对象

设置 type 属性以指定对象的类型。

对于 PowerShell,请使用:

  "type": "PowerShell",
  "inline": [ "string" ],
  "runAsSystem": "bool",
  "runElevated": "bool",
  "scriptUri": "string",
  "sha256Checksum": "string",
  "validExitCodes": [ "int" ]

对于 Shell,请使用:

  "type": "Shell",
  "inline": [ "string" ],
  "scriptUri": "string",
  "sha256Checksum": "string"

属性值

imageTemplates

名称 说明 Value
type 资源类型 “Microsoft.VirtualMachineImages/imageTemplates”
apiVersion 资源 API 版本 '2022-02-14'
name 资源名称 字符串 (必需)
location 资源所在的地理位置 字符串 (必需)
标记 资源标记。 标记名称和值的字典。 请参阅 模板中的标记
标识 映像模板的标识(如果已配置)。 需要 ImageTemplateIdentity ()
properties 映像模板的属性 ImageTemplateProperties

ImageTemplateIdentity

名称 说明 Value
type 用于映像模板的标识类型。 类型“None”将从映像模板中删除任何标识。 “None”
“UserAssigned”
userAssignedIdentities 与映像模板关联的用户标识列表。 用户标识字典键引用将是 ARM 资源 ID,格式为:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 对象 (object)

ImageTemplateProperties

名称 说明
buildTimeoutInMinutes 生成映像模板时等待的最长持续时间(包括所有自定义、验证和分发)。 省略或指定 0 以使用默认 (4 小时) 。 int
自定义 指定用于描述映像的自定义步骤的属性,如图像源等 ImageTemplateCustomizer[]
分发 (distribute) 映像输出需要转到的分发目标。 ImageTemplateDistributor[] (必需)
source 指定用于描述源图像的属性。 ImageTemplateSource (必需)
stagingResourceGroup 将用于生成映像的映像模板所在的订阅中的暂存资源组 ID。 如果此字段为空,则将创建具有随机名称的资源组。 如果此字段中指定的资源组不存在,则将使用相同的名称创建该资源组。 如果指定的资源组存在,则它必须为空,并且与映像模板位于同一区域中。 如果此字段为空或指定的资源组不存在,则在模板删除期间将删除创建的资源组,但如果指定的资源组存在,则在删除模板期间将删除在资源组中创建的资源,并且资源组本身将保留。 字符串
validate 要对生成的映像执行的配置选项和验证列表。 ImageTemplatePropertiesValidate
vmProfile 介绍如何设置虚拟机以生成映像 ImageTemplateVmProfile

ImageTemplateCustomizer

名称 说明
name 友好名称,提供有关此自定义步骤的用途的上下文 string
type 设置对象类型 File
PowerShell
Shell
WindowsRestart
WindowsUpdate (必需)

ImageTemplateFileCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “File” (必需)
destination 文件 (的绝对路径,其中包含已创建的嵌套目录结构) , (sourceUri) 的文件将上传到 VM 中 字符串
sha256Checksum 上述 sourceUri 字段中提供的文件的 SHA256 校验和 string
sourceUri 要上传用于自定义 VM 的文件的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 字符串

ImageTemplatePowerShellCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 需要“PowerShell” ()
inline 要执行的 PowerShell 命令数组 string[]
runAsSystem 如果指定,将使用本地系统用户以提升的权限运行 PowerShell 脚本。 仅当上面的 runElevated 字段设置为 true 时,才能为 true。 bool
runElevated 如果指定,将使用提升的权限运行 PowerShell 脚本 bool
scriptUri 要运行用于自定义的 PowerShell 脚本的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 string
sha256Checksum 上述 scriptUri 字段中提供的 power shell 脚本的 SHA256 校验和 字符串
validExitCodes PowerShell 脚本的有效退出代码。 [默认值:0] int[]

ImageTemplateShellCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 需要“Shell” ()
inline 要执行的 shell 命令数组 string[]
scriptUri 要运行用于自定义的 shell 脚本的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 字符串
sha256Checksum scriptUri 字段中提供的 shell 脚本的 SHA256 校验和 string

ImageTemplateRestartCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “WindowsRestart” (必需)
restartCheckCommand 重启成功时检查命令 [默认值:''] 字符串
restartCommand 用于执行重启的命令 [默认值:'shutdown /r /f /t 0 /c “packer restart”'] 字符串
restartTimeout 指定为数量级和单位字符串的重启超时,例如“5m” (5 分钟) 或“2h” (2 小时) [默认值:'5m'] 字符串

ImageTemplateWindowsUpdateCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “WindowsUpdate” (必需)
筛选器 要选择要应用的更新的筛选器数组。 省略或指定空数组以使用默认 (无筛选器) 。 有关此字段的示例和详细说明,请参阅上面的链接。 string[]
searchCriteria 搜索更新的条件。 省略或指定空字符串以使用默认 (搜索所有) 。 有关此字段的示例和详细说明,请参阅上面的链接。 string
updateLimit 一次应用的最大更新数。 省略或指定 0 以使用默认 (1000) int

ImageTemplateDistributor

名称 说明
artifactTags 分发服务器创建/更新项目后将应用于项目的标记。 对象 (object)
runOutputName 要用于关联的 RunOutput 的名称。 字符串 (必需)
类型 设置对象类型 ManagedImage
SharedImage
需要 VHD ()

ImageTemplateManagedImageDistributor

名称 说明 Value
type 分发类型。 需要“ManagedImage” ()
imageId 托管磁盘映像的资源 ID 字符串 (必需)
location 映像的 Azure 位置(如果映像已存在)应匹配 字符串 (必需)

ImageTemplateSharedImageDistributor

名称 说明 Value
type 分发类型。 需要“SharedImage” ()
excludeFromLatest 指示是否应从最新映像中排除创建的映像版本的标志。 省略以使用默认 (false) 。 bool
galleryImageId 共享映像库映像的资源 ID 字符串 (必需)
replicationRegions 映像将复制到的区域列表 string[] (必需)
storageAccountType 用于存储共享映像的存储帐户类型。 省略 以使用默认 (Standard_LRS) 。 “Standard_LRS”
“Standard_ZRS”

ImageTemplateVhdDistributor

名称 说明 Value
type 分发类型。 “VHD” (必需)

ImageTemplateSource

名称 说明 Value
type 设置对象类型 ManagedImage
PlatformImage
需要 SharedImageVersion ()

ImageTemplateManagedImageSource

名称 说明 Value
type 指定要开始使用的源映像的类型。 需要“ManagedImage” ()
imageId 客户订阅中托管映像的 ARM 资源 ID 字符串 (必需)

ImageTemplatePlatformImageSource

名称 说明 Value
type 指定要开始使用的源映像的类型。 “PlatformImage” (必需)
offer Azure 库映像中的映像产品/服务。 字符串
planInfo 平台映像的购买计划的可选配置。 PlatformImagePurchasePlan
发布者 Azure 库映像中的映像发布者。 字符串
sku Azure 库映像中的映像 SKU。 string
版本 Azure 库映像中的映像版本。 如果在此处指定了“latest”,则会在生成映像时评估版本,而不是在提交模板时评估版本。 string

PlatformImagePurchasePlan

名称 说明
planName 购买计划的名称。 字符串 (必需)
planProduct 购买计划的产品。 字符串 (必需)
planPublisher 购买计划的发布者。 字符串 (必需)

ImageTemplateSharedImageVersionSource

名称 说明 Value
type 指定要开始使用的源映像的类型。 需要“SharedImageVersion” ()
imageVersionId 共享映像库中映像版本的 ARM 资源 ID 字符串 (必需)

ImageTemplatePropertiesValidate

名称 说明
continueDistributeOnFailure 如果验证失败,并且此字段设置为 false,则不会分发输出图像 () 。 这是默认行为。 如果验证失败,并且此字段设置为 true,则仍会分发输出映像 () 。 请谨慎使用此选项,因为这可能会导致分发错误的映像以供使用。 在) (true 或 false 的情况下,在验证失败的情况下,端到端映像运行都将报告为失败。 [注意:如果验证成功,则此字段无效。] bool
inVMValidations 要执行的验证列表。 ImageTemplateInVMValidator[]
sourceValidationOnly 如果此字段设置为 true,将直接验证在“source”节中指定的图像。 不会运行单独的构建来生成,然后验证自定义映像。 bool

ImageTemplateInVMValidator

名称 说明
name 友好名称,用于提供此验证步骤的上下文 string
type 设置对象类型 PowerShell
需要 shell ()

ImageTemplatePowerShellValidator

名称 说明 Value
type 要在映像上使用的验证类型。 例如,“Shell”可以是 shell 验证 需要“PowerShell” ()
inline 要执行的 PowerShell 命令数组 string[]
runAsSystem 如果指定,将使用本地系统用户以提升的权限运行 PowerShell 脚本。 仅当上面的 runElevated 字段设置为 true 时,才能为 true。 bool
runElevated 如果指定,将使用提升的权限运行 PowerShell 脚本 bool
scriptUri 要运行进行验证的 PowerShell 脚本的 URI。 它可以是 github 链接、Azure 存储 URI 等 字符串
sha256Checksum 上述 scriptUri 字段中提供的 power shell 脚本的 SHA256 校验和 字符串
validExitCodes PowerShell 脚本的有效退出代码。 [默认值:0] int[]

ImageTemplateShellValidator

名称 说明 Value
type 要在映像上使用的验证类型。 例如,“Shell”可以是 shell 验证 需要“Shell” ()
inline 要执行的 shell 命令数组 string[]
scriptUri 要运行进行验证的 shell 脚本的 URI。 它可以是 github 链接、Azure 存储 URI 等 string
sha256Checksum scriptUri 字段中提供的 shell 脚本的 SHA256 校验和 字符串

ImageTemplateVmProfile

名称 说明
osDiskSizeGB OS 磁盘的大小(以 GB 为单位)。 省略或指定 0 以使用 Azure 的默认 OS 磁盘大小。 int
userAssignedIdentities 在生成 VM 和验证 VM 上配置的用户分配的托管标识的资源 ID 的可选数组。 这可能包括映像模板的标识。 string[]
vmSize 用于生成、自定义和捕获映像的虚拟机的大小。 省略或指定空字符串以对 Gen1 映像使用默认 (Standard_D1_v2,) 使用第 2 代映像的默认Standard_D2ds_v4。 string
vnetConfig 用于部署生成 VM 和验证 VM 的虚拟网络的可选配置。 如果不需要使用任何特定虚拟网络,则可将其省略。 VirtualNetworkConfig

VirtualNetworkConfig

名称 说明
proxyVmSize 用于将流量传递到生成 VM 和验证 VM 的代理虚拟机的大小。 省略或指定空字符串以使用默认 (Standard_A1_v2) 。 字符串
subnetId 预先存在的子网的资源 ID。 字符串

快速入门模板

以下快速入门模板部署此资源类型。

模板 说明
使用 Azure Windows 基线的 Azure 映像生成器

部署到 Azure
创建 Azure 映像生成器环境,并生成应用了最新 Windows 汇报和 Azure Windows 基线的 Windows Server 映像。
配置 Dev Box 服务

部署到 Azure
此模板将按照 Dev Box 快速入门指南创建所有 Dev Box 管理员资源。 可以查看创建的所有资源,也可以直接转到 DevPortal.microsoft.com 创建第一个 Dev Box。

Terraform (AzAPI 提供程序) 资源定义

imageTemplates 资源类型可以部署到:

  • 资源组

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.VirtualMachineImages/imageTemplates 资源,请将以下 Terraform 添加到模板。

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.VirtualMachineImages/imageTemplates@2022-02-14"
  name = "string"
  location = "string"
  parent_id = "string"
  tags = {
    tagName1 = "tagValue1"
    tagName2 = "tagValue2"
  }
  identity {
    type =  "UserAssigned"
    identity_ids = []
  }
  body = jsonencode({
    properties = {
      buildTimeoutInMinutes = int
      customize = [
        {
          name = "string"
          type = "string"
          // For remaining properties, see ImageTemplateCustomizer objects
        }
      ]
      distribute = [
        {
          artifactTags = {}
          runOutputName = "string"
          type = "string"
          // For remaining properties, see ImageTemplateDistributor objects
        }
      ]
      source = {
        type = "string"
        // For remaining properties, see ImageTemplateSource objects
      }
      stagingResourceGroup = "string"
      validate = {
        continueDistributeOnFailure = bool
        inVMValidations = [
          {
            name = "string"
            type = "string"
            // For remaining properties, see ImageTemplateInVMValidator objects
          }
        ]
        sourceValidationOnly = bool
      }
      vmProfile = {
        osDiskSizeGB = int
        userAssignedIdentities = [
          "string"
        ]
        vmSize = "string"
        vnetConfig = {
          proxyVmSize = "string"
          subnetId = "string"
        }
      }
    }
  })
}

ImageTemplateCustomizer 对象

设置 type 属性以指定对象的类型。

对于 “文件”,请使用:

  type = "File"
  destination = "string"
  sha256Checksum = "string"
  sourceUri = "string"

对于 PowerShell,请使用:

  type = "PowerShell"
  inline = [
    "string"
  ]
  runAsSystem = bool
  runElevated = bool
  scriptUri = "string"
  sha256Checksum = "string"
  validExitCodes = [
    int
  ]

对于 Shell,请使用:

  type = "Shell"
  inline = [
    "string"
  ]
  scriptUri = "string"
  sha256Checksum = "string"

对于 WindowsRestart,请使用:

  type = "WindowsRestart"
  restartCheckCommand = "string"
  restartCommand = "string"
  restartTimeout = "string"

对于 WindowsUpdate,请使用:

  type = "WindowsUpdate"
  filters = [
    "string"
  ]
  searchCriteria = "string"
  updateLimit = int

ImageTemplateDistributor 对象

设置 type 属性以指定对象的类型。

对于 ManagedImage,请使用:

  type = "ManagedImage"
  imageId = "string"
  location = "string"

对于 SharedImage,请使用:

  type = "SharedImage"
  excludeFromLatest = bool
  galleryImageId = "string"
  replicationRegions = [
    "string"
  ]
  storageAccountType = "string"

对于 VHD,请使用:

  type = "VHD"

ImageTemplateSource 对象

设置 type 属性以指定对象的类型。

对于 ManagedImage,请使用:

  type = "ManagedImage"
  imageId = "string"

对于 PlatformImage,请使用:

  type = "PlatformImage"
  offer = "string"
  planInfo = {
    planName = "string"
    planProduct = "string"
    planPublisher = "string"
  }
  publisher = "string"
  sku = "string"
  version = "string"

对于 SharedImageVersion,请使用:

  type = "SharedImageVersion"
  imageVersionId = "string"

ImageTemplateInVMValidator 对象

设置 type 属性以指定对象的类型。

对于 PowerShell,请使用:

  type = "PowerShell"
  inline = [
    "string"
  ]
  runAsSystem = bool
  runElevated = bool
  scriptUri = "string"
  sha256Checksum = "string"
  validExitCodes = [
    int
  ]

对于 Shell,请使用:

  type = "Shell"
  inline = [
    "string"
  ]
  scriptUri = "string"
  sha256Checksum = "string"

属性值

imageTemplates

名称 说明 Value
type 资源类型 “Microsoft.VirtualMachineImages/imageTemplates@2022-02-14”
name 资源名称 字符串 (必需)
location 资源所在的地理位置 字符串 (必需)
parent_id 若要部署到资源组,请使用该资源组的 ID。 字符串 (必需)
标记 资源标记。 标记名称和值的字典。
标识 映像模板的标识(如果已配置)。 需要 ImageTemplateIdentity ()
properties 映像模板的属性 ImageTemplateProperties

ImageTemplateIdentity

名称 说明 Value
type 用于映像模板的标识类型。 类型“None”将从映像模板中删除任何标识。 “UserAssigned”
identity_ids 与映像模板关联的用户标识列表。 用户标识字典键引用将是 ARM 资源 ID,格式为:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 用户标识 ID 的数组。

ImageTemplateProperties

名称 说明
buildTimeoutInMinutes 生成映像模板时等待的最长持续时间(包括所有自定义、验证和分发)。 省略或指定 0 以使用默认 (4 小时) 。 int
自定义 指定用于描述映像的自定义步骤的属性,如图像源等 ImageTemplateCustomizer[]
分发 (distribute) 映像输出需要转到的分发目标。 ImageTemplateDistributor[] (必需)
source 指定用于描述源图像的属性。 ImageTemplateSource (必需)
stagingResourceGroup 将用于生成映像的映像模板所在的订阅中的暂存资源组 ID。 如果此字段为空,则将创建具有随机名称的资源组。 如果此字段中指定的资源组不存在,则将使用相同的名称创建该资源组。 如果指定的资源组存在,则它必须为空,并且与映像模板位于同一区域中。 如果此字段为空或指定的资源组不存在,则在模板删除期间将删除创建的资源组,但如果指定的资源组存在,则在删除模板期间将删除在资源组中创建的资源,并且资源组本身将保留。 字符串
validate 要对生成的映像执行的配置选项和验证列表。 ImageTemplatePropertiesValidate
vmProfile 介绍如何设置虚拟机以生成映像 ImageTemplateVmProfile

ImageTemplateCustomizer

名称 说明
name 友好名称,提供有关此自定义步骤的用途的上下文 string
type 设置对象类型 File
PowerShell
Shell
WindowsRestart
WindowsUpdate (必需)

ImageTemplateFileCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “File” (必需)
destination 文件 (的绝对路径,其中包含已创建的嵌套目录结构) , (sourceUri) 的文件将上传到 VM 中 string
sha256Checksum 上述 sourceUri 字段中提供的文件的 SHA256 校验和 字符串
sourceUri 要上传用于自定义 VM 的文件的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 string

ImageTemplatePowerShellCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 需要“PowerShell” ()
inline 要执行的 PowerShell 命令数组 string[]
runAsSystem 如果指定,将使用本地系统用户以提升的权限运行 PowerShell 脚本。 仅当上面的 runElevated 字段设置为 true 时,才能为 true。 bool
runElevated 如果指定,将使用提升的权限运行 PowerShell 脚本 bool
scriptUri 要运行用于自定义的 PowerShell 脚本的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 字符串
sha256Checksum 上述 scriptUri 字段中提供的 power shell 脚本的 SHA256 校验和 字符串
validExitCodes PowerShell 脚本的有效退出代码。 [默认值:0] int[]

ImageTemplateShellCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “Shell” (必需)
inline 要执行的 shell 命令数组 string[]
scriptUri 要运行用于自定义的 shell 脚本的 URI。 它可以是 github 链接、Azure 存储的 SAS URI 等 string
sha256Checksum scriptUri 字段中提供的 shell 脚本的 SHA256 校验和 字符串

ImageTemplateRestartCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 需要“WindowsRestart” ()
restartCheckCommand 重启成功时检查命令 [默认值:''] 字符串
restartCommand 用于执行重启的命令 [默认值:'shutdown /r /f /t 0 /c “packer restart”'] 字符串
restartTimeout 指定为数量级和单位字符串的重启超时,例如“5m” (5 分钟) 或“2h” (2 小时) [默认值:'5m'] 字符串

ImageTemplateWindowsUpdateCustomizer

名称 说明 Value
type 要在映像上使用的自定义工具的类型。 例如,“Shell”可以是 shell 定制器 “WindowsUpdate” (必需)
筛选器 要选择要应用的更新的筛选器数组。 省略或指定空数组以使用默认 (无筛选器) 。 有关此字段的示例和详细说明,请参阅上面的链接。 string[]
searchCriteria 搜索更新的条件。 省略或指定空字符串以使用默认 (搜索所有) 。 有关此字段的示例和详细说明,请参阅上面的链接。 字符串
updateLimit 一次应用的最大更新数。 省略或指定 0 以使用默认 (1000) int

ImageTemplateDistributor

名称 说明
artifactTags 分发服务器创建/更新项目后将应用于项目的标记。 对象 (object)
runOutputName 要用于关联的 RunOutput 的名称。 字符串 (必需)
类型 设置对象类型 ManagedImage
SharedImage
需要 VHD ()

ImageTemplateManagedImageDistributor

名称 说明 Value
type 分发类型。 “ManagedImage” (需要)
imageId 托管磁盘映像的资源 ID 字符串 (必需)
location 映像的 Azure 位置(如果映像已存在)应匹配 字符串 (必需)

ImageTemplateSharedImageDistributor

名称 说明 Value
type 分发类型。 需要“SharedImage” ()
excludeFromLatest 指示是否应从最新映像中排除创建的映像版本的标志。 省略以使用默认 (false) 。 bool
galleryImageId 共享映像库映像的资源 ID 字符串 (必需)
replicationRegions 映像将复制到的区域列表 string[] (必需)
storageAccountType 用于存储共享映像的存储帐户类型。 省略 以使用默认 (Standard_LRS) 。 “Standard_LRS”
“Standard_ZRS”

ImageTemplateVhdDistributor

名称 说明 Value
type 分发类型。 需要“VHD” ()

ImageTemplateSource

名称 说明 Value
type 设置对象类型 ManagedImage
PlatformImage
需要 SharedImageVersion ()

ImageTemplateManagedImageSource

名称 说明 Value
type 指定要从头开始使用的源图像的类型。 “ManagedImage” (必需)
imageId 客户订阅中托管映像的 ARM 资源 ID 字符串 (必需)

ImageTemplatePlatformImageSource

名称 说明 Value
type 指定要从头开始使用的源图像的类型。 “PlatformImage” (必需)
offer Azure 库映像中的映像套餐。 字符串
planInfo 平台映像的购买计划的可选配置。 PlatformImagePurchasePlan
发布者 Azure 库映像中的映像发布服务器。 字符串
sku Azure 库映像中的映像 SKU。 string
版本 Azure 库映像中的映像版本。 如果此处指定了“latest”,则会在生成映像时评估版本,而不是在提交模板时评估版本。 string

PlatformImagePurchasePlan

名称 说明
planName 购买计划的名称。 字符串 (必需)
planProduct 购买计划的产品。 字符串 (必需)
planPublisher 购买计划的发布者。 字符串 (必需)

ImageTemplateSharedImageVersionSource

名称 说明 Value
type 指定要从头开始使用的源图像的类型。 需要“SharedImageVersion” ()
imageVersionId 共享映像库中映像版本的 ARM 资源 ID 字符串 (必需)

ImageTemplatePropertiesValidate

名称 说明
continueDistributeOnFailure 如果验证失败,并且此字段设置为 false,则不会分发输出映像 () 。 这是默认行为。 如果验证失败且此字段设置为 true,则仍会分发输出映像 () 。 请谨慎使用此选项,因为这可能会导致分发错误的映像以供使用。 在 (true 或 false) 的任一情况下,在验证失败时,端到端映像运行都将报告为失败。 [注意:如果验证成功,则此字段无效。] bool
inVMValidations 要执行的验证列表。 ImageTemplateInVMValidator[]
sourceValidationOnly 如果此字段设置为 true,将直接验证在“source”节中指定的图像。 不会运行单独的构建来生成,然后验证自定义映像。 bool

ImageTemplateInVMValidator

名称 说明
name 友好名称,用于提供有关此验证步骤的上下文 字符串
type 设置对象类型 PowerShell
需要 shell ()

ImageTemplatePowerShellValidator

名称 说明 Value
type 要对映像使用的验证类型。 例如,“Shell”可以是 shell 验证 “PowerShell” (必需)
inline 要执行的 PowerShell 命令数组 string[]
runAsSystem 如果指定,将使用本地系统用户以提升的权限运行 PowerShell 脚本。 仅当上面的 runElevated 字段设置为 true 时,才能为 true。 bool
runElevated 如果指定,则 PowerShell 脚本将使用提升的权限运行 bool
scriptUri 要运行用于验证的 PowerShell 脚本的 URI。 它可以是 github 链接、Azure 存储 URI 等 字符串
sha256Checksum 上面的 scriptUri 字段中提供的 power shell 脚本的 SHA256 校验和 字符串
validExitCodes PowerShell 脚本的有效退出代码。 [默认值:0] int[]

ImageTemplateShellValidator

名称 说明 Value
type 要对映像使用的验证类型。 例如,“Shell”可以是 shell 验证 需要“Shell” ()
inline 要执行的 shell 命令数组 string[]
scriptUri 要运行用于验证的 shell 脚本的 URI。 它可以是 github 链接、Azure 存储 URI 等 字符串
sha256Checksum scriptUri 字段中提供的 shell 脚本的 SHA256 校验和 字符串

ImageTemplateVmProfile

名称 说明
osDiskSizeGB OS 磁盘的大小(以 GB 为单位)。 省略或指定 0 以使用 Azure 的默认 OS 磁盘大小。 int
userAssignedIdentities 在生成 VM 和验证 VM 上配置的用户分配的托管标识的资源 ID 的可选数组。 这可能包括映像模板的标识。 string[]
vmSize 用于生成、自定义和捕获映像的虚拟机的大小。 省略或指定空字符串,以使用 Gen1 映像的默认 (Standard_D1_v2,Standard_D2ds_v4第 2 代映像) 。 字符串
vnetConfig 用于部署生成 VM 和验证 VM 的虚拟网络的可选配置。 如果不需要使用任何特定虚拟网络,则可将其省略。 VirtualNetworkConfig

VirtualNetworkConfig

名称 说明
proxyVmSize 用于将流量传递到生成 VM 和验证 VM 的代理虚拟机的大小。 省略或指定空字符串以使用默认 (Standard_A1_v2) 。 string
subnetId 预先存在的子网的资源 ID。 字符串