Microsoft.VirtualMachineImages imageTemplates

Bicep 资源定义

可以使用目标操作部署 imageTemplates 资源类型:

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

资源格式

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

resource symbolicname 'Microsoft.VirtualMachineImages/imageTemplates@2024-02-01' = {
  identity: {
    type: 'string'
    userAssignedIdentities: {
      {customized property}: {}
    }
  }
  location: 'string'
  name: 'string'
  properties: {
    autoRun: {
      state: 'string'
    }
    buildTimeoutInMinutes: int
    customize: [
      {
        name: 'string'
        type: 'string'
        // For remaining properties, see ImageTemplateCustomizer objects
      }
    ]
    distribute: [
      {
        artifactTags: {
          {customized property}: 'string'
        }
        runOutputName: 'string'
        type: 'string'
        // For remaining properties, see ImageTemplateDistributor objects
      }
    ]
    errorHandling: {
      onCustomizerError: 'string'
      onValidationError: 'string'
    }
    managedResourceTags: {
      {customized property}: 'string'
    }
    optimize: {
      vmBoot: {
        state: 'string'
      }
    }
    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: {
        containerInstanceSubnetId: 'string'
        proxyVmSize: 'string'
        subnetId: 'string'
      }
    }
  }
  tags: {
    {customized property}: 'string'
  }
}

ImageTemplateCustomizer 对象

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

对于 文件,请使用:

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

对于 PowerShell,请使用:

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

对于 Shell,请使用:

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

对于 WindowsRestart,请使用:

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

对于 windowsUpdate ,请使用:

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

DistributVersioner 对象

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

对于 最新,请使用:

{
  major: int
  scheme: 'Latest'
}

对于 ,请使用:

{
  scheme: 'Source'
}

ImageTemplateSource 对象

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

对于 managedImage,请使用:

{
  imageId: 'string'
  type: 'ManagedImage'
}

对于 PlatformImage,请使用:

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

对于 SharedImageVersion,请使用:

{
  imageVersionId: 'string'
  type: 'SharedImageVersion'
}

ImageTemplateInVMValidator 对象

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

对于 文件,请使用:

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

对于 PowerShell,请使用:

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

对于 Shell,请使用:

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

ImageTemplateDistributor 对象

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

对于 managedImage,请使用:

{
  imageId: 'string'
  location: 'string'
  type: 'ManagedImage'
}

对于 SharedImage,请使用:

{
  excludeFromLatest: bool
  galleryImageId: 'string'
  replicationRegions: [
    'string'
  ]
  storageAccountType: 'string'
  targetRegions: [
    {
      name: 'string'
      replicaCount: int
      storageAccountType: 'string'
    }
  ]
  type: 'SharedImage'
  versioning: {
    scheme: 'string'
    // For remaining properties, see DistributeVersioner objects
  }
}

对于 VHD,请使用:

{
  type: 'VHD'
  uri: 'string'
}

属性值

DistributVersioner

名字 描述 价值
方案 对于 DistributVersionerLatest类型,设置为“Latest”。 设置为 DistributVersionerSource类型的“源”。 “Latest”
“Source”(必需)

DistributVersionerLatest

名字 描述 价值
主要 生成的版本号的主要版本。 根据此值作为主要版本的版本确定什么是“最新”。 -1 等效于将其保留为未设置。 int

约束:
最小值 = -1
方案 要使用的版本号方案。 “Latest”(必需)

DistributeVersionerSource

名字 描述 价值
方案 要使用的版本号方案。 “Source”(必需)

ImageTemplateAutoRun

名字 描述 价值
启用此字段将在创建或更新映像模板时触发自动生成。 “Disabled”
“Enabled”

ImageTemplateCustomizer

名字 描述 价值
名字 用于提供此自定义步骤的上下文的友好名称 字符串
类型 对于 imageTemplateFileCustomizer,请设置为“File”。 对于 imageTemplatePowerShellCustomizer,请设置为“PowerShell”。 对于 imageTemplateShellCustomizer,请设置为类型 “Shell”。 对于 imageTemplateRestartCustomizer,请设置为 “WindowsRestart”。 对于 imageTemplateWindowsUpdateCustomizer类型,设置为“WindowsUpdate”。 “File”
“PowerShell”
“Shell”
“WindowsRestart”
“WindowsUpdate”(必需)

ImageTemplateDistributor

名字 描述 价值
artifactTags 分发服务器创建/更新项目后,将应用于项目的标记。 ImageTemplateDistributorArtifactTags
runOutputName 要用于关联的 RunOutput 的名称。 字符串

约束:
模式 = ^[A-Za-z0-9-_.]{1,64}$ (必需)
类型 对于 ImageTemplateManagedImageDistributor类型,设置为“ManagedImage”。 对于 ImageTemplateSharedImageDistributor类型,设置为“SharedImage”。 对于 imageTemplateVhdDistributor ,请设置为“VHD”。 “ManagedImage”
“SharedImage”
“VHD”(必需)

ImageTemplateDistributorArtifactTags

名字 描述 价值

ImageTemplateFileCustomizer

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

ImageTemplateFileValidator

名字 描述 价值
目的地 文件(已创建嵌套目录结构)的绝对路径,该文件(来自 sourceUri)将上传到 VM 中 字符串
sha256Checksum 上述 sourceUri 字段中提供的文件的 SHA256 校验和 字符串
sourceUri 要上传到 VM 进行验证的文件的 URI。 它可以是 github 链接、Azure 存储 URI(已授权或 SAS),等等 字符串
类型 要在映像上使用的验证类型。 例如,“Shell”可以是 shell 验证 “File”(必需)

ImageTemplateIdentity

名字 描述 价值
类型 用于映像模板的标识类型。 类型“None”将从映像模板中删除任何标识。 “None”
“UserAssigned”
userAssignedIdentities 与资源关联的用户分配标识集。 userAssignedIdentities 字典密钥将为 ARM 资源 ID,格式为“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 字典值可以是请求中的空对象({})。 UserAssignedIdentities

ImageTemplateInVMValidator

名字 描述 价值
名字 用于提供此验证步骤的上下文的友好名称 字符串
类型 对于 imageTemplateFileValidator,请设置为“File”。 对于 imageTemplatePowerShellValidator类型,设置为“PowerShell”。 对于 imageTemplateShellValidator类型,设置为“Shell”。 “File”
“PowerShell”
“Shell”(必需)

ImageTemplateManagedImageDistributor

名字 描述 价值
imageId 托管磁盘映像的资源 ID string (必需)
位置 映像的 Azure 位置应匹配(如果映像已存在) string (必需)
类型 分布类型。 “ManagedImage”(必需)

ImageTemplateManagedImageSource

名字 描述 价值
imageId 客户订阅中托管映像的 ARM 资源 ID string (必需)
类型 指定要从其开始的源图像的类型。 “ManagedImage”(必需)

ImageTemplatePlatformImageSource

名字 描述 价值
提供 azure 库映像映像产品/服务。 字符串
planInfo 平台映像的购买计划的可选配置。 PlatformImagePurchasePlan
发行人 Azure 库映像中的映像发布服务器 字符串
sku Azure 库映像中的映像 SKU。 字符串
类型 指定要从其开始的源图像的类型。 “PlatformImage”(必需)
版本 Azure 库映像中的映像版本。 如果在此处指定了“latest”,则会在映像生成发生时评估版本,而不是提交模板时评估版本。 字符串

ImageTemplatePowerShellCustomizer

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

ImageTemplatePowerShellValidator

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

ImageTemplateProperties

名字 描述 价值
autoRun 指示是否在创建或更新模板时自动运行映像模板生成。 ImageTemplateAutoRun
buildTimeoutInMinutes 生成映像模板时等待的最大持续时间(包括所有自定义、优化、验证和分发)。 省略或指定 0 以使用默认值 (4 小时)。 int

约束:
最小值 = 0
最大值 = 960
自定义 指定用于描述映像的自定义步骤的属性,如图像源等 ImageTemplateCustomizer[]
分发 映像输出需要转到的分发目标。 ImageTemplateDistributor[] (必需)
errorHandling 生成失败时的错误处理选项 ImageTemplatePropertiesErrorHandling
managedResourceTags 将应用于服务创建的资源组和/或资源的标记。 ImageTemplatePropertiesManagedResourceTags
优化 指定要对图像执行的优化。 ImageTemplatePropertiesOptimize
指定用于描述源图像的属性。 ImageTemplateSource (必需)
stagingResourceGroup 与用于生成映像的映像模板相同的订阅中的暂存资源组 ID。 如果此字段为空,则会创建一个具有随机名称的资源组。 如果此字段中指定的资源组不存在,则会创建具有相同名称的资源组。 如果指定的资源组存在,则它必须是空的,并且与映像模板位于同一区域中。 如果此字段为空或指定的资源组不存在,则在模板删除期间将删除创建的资源组,但在模板删除期间将删除资源组中创建的资源,并且资源组本身将保留。 字符串
驗證 要对生成的映像执行的验证的配置选项和列表。 ImageTemplatePropertiesValidate
vmProfile 描述如何设置虚拟机以生成映像 ImageTemplateVmProfile

ImageTemplatePropertiesErrorHandling

名字 描述 价值
onCustomizerError 如果存在定制器错误,并且此字段设置为“清理”,则会清理生成 VM 和关联的网络资源。 这是默认行为。 如果存在定制器错误,并且此字段设置为“中止”,将保留生成 VM。 “abort”
“cleanup”
onValidationError 如果存在验证错误,并且此字段设置为“清理”,则会清理生成 VM 和关联的网络资源。 这是默认行为。 如果存在验证错误,并且此字段设置为“中止”,将保留生成 VM。 “abort”
“cleanup”

ImageTemplatePropertiesManagedResourceTags

名字 描述 价值

ImageTemplatePropertiesOptimize

名字 描述 价值
vmBoot 优化在映像上应用,以便更快地启动 VM。 ImageTemplatePropertiesOptimizeVmBoot

ImageTemplatePropertiesOptimizeVmBoot

名字 描述 价值
启用此字段将通过优化最终自定义映像输出来提高 VM 启动时间。 “Disabled”
“Enabled”

ImageTemplatePropertiesValidate

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

ImageTemplateRestartCustomizer

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

ImageTemplateSharedImageDistributor

名字 描述 价值
excludeFromLatest 指示是否应从最新版本中排除创建的映像版本的标志。 省略使用默认值(false)。 bool
galleryImageId Azure 计算库映像的资源 ID string (必需)
replicationRegions [已弃用]将映像复制到的区域列表。 仅当未指定 targetRegions 时,才能指定此列表。 此字段已弃用 - 请改用 targetRegions。 string[]
storageAccountType [已弃用]用于存储共享映像的存储帐户类型。 省略使用默认值(Standard_LRS)。 仅当指定 replicationRegions 时,才能指定此字段。 此字段已弃用 - 请改用 targetRegions。 “Premium_LRS”
“Standard_LRS”
“Standard_ZRS”
targetRegions 要将分布式映像版本复制到的目标区域。 此对象取代 replicationRegions,仅当未指定 replicationRegions 时才能指定。 TargetRegion[]
类型 分布类型。 “SharedImage”(必需)
versioning 介绍如何为分发生成新的 x.y.z 版本号。 DistributVersioner

ImageTemplateSharedImageVersionSource

名字 描述 价值
imageVersionId 映像版本的 ARM 资源 ID。 当映像版本名称为“latest”时,将在映像生成发生时评估版本。 string (必需)
类型 指定要从其开始的源图像的类型。 “SharedImageVersion”(必需)

ImageTemplateShellCustomizer

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

ImageTemplateShellValidator

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

ImageTemplateSource

名字 描述 价值
类型 对于 ImageTemplateManagedImageSource,请设置为“ManagedImage”。 设置为 ImageTemplatePlatformImageSource类型的“PlatformImage”。 对于 ImageTemplateSharedImageVersionSource,请设置为“SharedImageVersion”。 “ManagedImage”
“PlatformImage”
“SharedImageVersion”(必需)

ImageTemplateVhdDistributor

名字 描述 价值
类型 分布类型。 “VHD”(必需)
uri 分布式 VHD Blob 的可选 Azure 存储 URI。 省略使用默认的(空字符串),在这种情况下,VHD 将发布到暂存资源组中的存储帐户。 字符串

ImageTemplateVmProfile

名字 描述 价值
osDiskSizeGB OS 磁盘的大小(以 GB 为单位)。 省略或指定 0 以使用 Azure 的默认 OS 磁盘大小。 int

约束:
最小值 = 0
userAssignedIdentities 要在生成 VM 和验证 VM 上配置的用户分配托管标识的资源 ID 的可选数组。 这可能包括映像模板的标识。 string[]
vmSize 用于生成、自定义和捕获映像的虚拟机的大小。 省略或指定空字符串以使用默认值(第 1 代映像Standard_D1_v2,并为 Gen2 映像指定Standard_D2ds_v4)。 字符串
vnetConfig 用于部署生成 VM 和验证 VM 的虚拟网络的可选配置。 如果不需要使用任何特定的虚拟网络,则省略。 VirtualNetworkConfig

ImageTemplateWindowsUpdateCustomizer

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

约束:
最小值 = 0

Microsoft.VirtualMachineImages/imageTemplates

名字 描述 价值
身份 映像模板的标识(如果已配置)。 ImageTemplateIdentity (必需)
位置 资源所在的地理位置 string (必需)
名字 资源名称 字符串

约束:
模式 = ^[A-Za-z0-9-_.]{1,64}$ (必需)
性能 映像模板的属性 ImageTemplateProperties
标签 资源标记 标记名称和值的字典。 请参阅模板 中的 标记

PlatformImagePurchasePlan

名字 描述 价值
planName 购买计划的名称。 string (必需)
planProduct 购买计划的产品。 string (必需)
planPublisher 购买计划的发布者。 string (必需)

TargetRegion

名字 描述 价值
名字 区域的名称。 string (必需)
replicaCount 要在此区域中创建的映像版本的副本数。 省略使用默认值 (1)。 int

约束:
最小值 = 1
storageAccountType 指定要用于在此区域中存储映像的存储帐户类型。 省略使用默认值(Standard_LRS)。 “Premium_LRS”
“Standard_LRS”
“Standard_ZRS”

TrackedResourceTags

名字 描述 价值

UserAssignedIdentities

名字 描述 价值

UserAssignedIdentity

名字 描述 价值

VirtualNetworkConfig

名字 描述 价值
containerInstanceSubnetId 将为其部署 Azure 容器实例以供独立生成部署的预先存在的子网的资源 ID。 仅当同时指定 subnetId 并且必须与 subnetId中指定的子网位于同一虚拟网络中时,才能指定此字段。 字符串
proxyVmSize 用于将流量传递到生成 VM 和验证 VM 的代理虚拟机的大小。 如果未指定 containerInstanceSubnetId,则不能指定此项,因为在这种情况下没有部署代理虚拟机。 省略或指定空字符串以使用默认值(Standard_A1_v2)。 字符串
subnetId 将部署生成 VM 和验证 VM 的预先存在的子网的资源 ID 字符串

用法示例

Azure 验证模块

以下 Azure 验证模块 可用于部署此资源类型。

模块 描述
虚拟机映像模板 虚拟机映像模板的 AVM 资源模块

Azure 快速入门示例

以下 Azure 快速入门模板 包含用于部署此资源类型的 Bicep 示例。

Bicep 文件 描述
使用 Azure Windows 基线 Azure 映像生成器 创建 Azure 映像生成器环境,并生成应用最新 Windows 更新和 Azure Windows 基线的 Windows Server 映像。
配置 Dev Box 服务 此模板将按照 Dev Box 快速入门指南(/azure/dev-box/quickstart-create-dev-box)创建所有 Dev Box 管理员资源。 可以查看创建的所有资源,也可以直接转到 DevPortal.microsoft.com 创建第一个 Dev Box。

ARM 模板资源定义

可以使用目标操作部署 imageTemplates 资源类型:

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

资源格式

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

{
  "type": "Microsoft.VirtualMachineImages/imageTemplates",
  "apiVersion": "2024-02-01",
  "name": "string",
  "identity": {
    "type": "string",
    "userAssignedIdentities": {
      "{customized property}": {
      }
    }
  },
  "location": "string",
  "properties": {
    "autoRun": {
      "state": "string"
    },
    "buildTimeoutInMinutes": "int",
    "customize": [ {
      "name": "string",
      "type": "string"
      // For remaining properties, see ImageTemplateCustomizer objects
    } ],
    "distribute": [ {
      "artifactTags": {
        "{customized property}": "string"
      },
      "runOutputName": "string",
      "type": "string"
      // For remaining properties, see ImageTemplateDistributor objects
    } ],
    "errorHandling": {
      "onCustomizerError": "string",
      "onValidationError": "string"
    },
    "managedResourceTags": {
      "{customized property}": "string"
    },
    "optimize": {
      "vmBoot": {
        "state": "string"
      }
    },
    "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": {
        "containerInstanceSubnetId": "string",
        "proxyVmSize": "string",
        "subnetId": "string"
      }
    }
  },
  "tags": {
    "{customized property}": "string"
  }
}

ImageTemplateCustomizer 对象

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

对于 文件,请使用:

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

对于 PowerShell,请使用:

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

对于 Shell,请使用:

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

对于 WindowsRestart,请使用:

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

对于 windowsUpdate ,请使用:

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

DistributVersioner 对象

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

对于 最新,请使用:

{
  "major": "int",
  "scheme": "Latest"
}

对于 ,请使用:

{
  "scheme": "Source"
}

ImageTemplateSource 对象

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

对于 managedImage,请使用:

{
  "imageId": "string",
  "type": "ManagedImage"
}

对于 PlatformImage,请使用:

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

对于 SharedImageVersion,请使用:

{
  "imageVersionId": "string",
  "type": "SharedImageVersion"
}

ImageTemplateInVMValidator 对象

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

对于 文件,请使用:

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

对于 PowerShell,请使用:

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

对于 Shell,请使用:

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

ImageTemplateDistributor 对象

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

对于 managedImage,请使用:

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

对于 SharedImage,请使用:

{
  "excludeFromLatest": "bool",
  "galleryImageId": "string",
  "replicationRegions": [ "string" ],
  "storageAccountType": "string",
  "targetRegions": [
    {
      "name": "string",
      "replicaCount": "int",
      "storageAccountType": "string"
    }
  ],
  "type": "SharedImage",
  "versioning": {
    "scheme": "string"
    // For remaining properties, see DistributeVersioner objects
  }
}

对于 VHD,请使用:

{
  "type": "VHD",
  "uri": "string"
}

属性值

DistributVersioner

名字 描述 价值
方案 对于 DistributVersionerLatest类型,设置为“Latest”。 设置为 DistributVersionerSource类型的“源”。 “Latest”
“Source”(必需)

DistributVersionerLatest

名字 描述 价值
主要 生成的版本号的主要版本。 根据此值作为主要版本的版本确定什么是“最新”。 -1 等效于将其保留为未设置。 int

约束:
最小值 = -1
方案 要使用的版本号方案。 “Latest”(必需)

DistributeVersionerSource

名字 描述 价值
方案 要使用的版本号方案。 “Source”(必需)

ImageTemplateAutoRun

名字 描述 价值
启用此字段将在创建或更新映像模板时触发自动生成。 “Disabled”
“Enabled”

ImageTemplateCustomizer

名字 描述 价值
名字 用于提供此自定义步骤的上下文的友好名称 字符串
类型 对于 imageTemplateFileCustomizer,请设置为“File”。 对于 imageTemplatePowerShellCustomizer,请设置为“PowerShell”。 对于 imageTemplateShellCustomizer,请设置为类型 “Shell”。 对于 imageTemplateRestartCustomizer,请设置为 “WindowsRestart”。 对于 imageTemplateWindowsUpdateCustomizer类型,设置为“WindowsUpdate”。 “File”
“PowerShell”
“Shell”
“WindowsRestart”
“WindowsUpdate”(必需)

ImageTemplateDistributor

名字 描述 价值
artifactTags 分发服务器创建/更新项目后,将应用于项目的标记。 ImageTemplateDistributorArtifactTags
runOutputName 要用于关联的 RunOutput 的名称。 字符串

约束:
模式 = ^[A-Za-z0-9-_.]{1,64}$ (必需)
类型 对于 ImageTemplateManagedImageDistributor类型,设置为“ManagedImage”。 对于 ImageTemplateSharedImageDistributor类型,设置为“SharedImage”。 对于 imageTemplateVhdDistributor ,请设置为“VHD”。 “ManagedImage”
“SharedImage”
“VHD”(必需)

ImageTemplateDistributorArtifactTags

名字 描述 价值

ImageTemplateFileCustomizer

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

ImageTemplateFileValidator

名字 描述 价值
目的地 文件(已创建嵌套目录结构)的绝对路径,该文件(来自 sourceUri)将上传到 VM 中 字符串
sha256Checksum 上述 sourceUri 字段中提供的文件的 SHA256 校验和 字符串
sourceUri 要上传到 VM 进行验证的文件的 URI。 它可以是 github 链接、Azure 存储 URI(已授权或 SAS),等等 字符串
类型 要在映像上使用的验证类型。 例如,“Shell”可以是 shell 验证 “File”(必需)

ImageTemplateIdentity

名字 描述 价值
类型 用于映像模板的标识类型。 类型“None”将从映像模板中删除任何标识。 “None”
“UserAssigned”
userAssignedIdentities 与资源关联的用户分配标识集。 userAssignedIdentities 字典密钥将为 ARM 资源 ID,格式为“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 字典值可以是请求中的空对象({})。 UserAssignedIdentities

ImageTemplateInVMValidator

名字 描述 价值
名字 用于提供此验证步骤的上下文的友好名称 字符串
类型 对于 imageTemplateFileValidator,请设置为“File”。 对于 imageTemplatePowerShellValidator类型,设置为“PowerShell”。 对于 imageTemplateShellValidator类型,设置为“Shell”。 “File”
“PowerShell”
“Shell”(必需)

ImageTemplateManagedImageDistributor

名字 描述 价值
imageId 托管磁盘映像的资源 ID string (必需)
位置 映像的 Azure 位置应匹配(如果映像已存在) string (必需)
类型 分布类型。 “ManagedImage”(必需)

ImageTemplateManagedImageSource

名字 描述 价值
imageId 客户订阅中托管映像的 ARM 资源 ID string (必需)
类型 指定要从其开始的源图像的类型。 “ManagedImage”(必需)

ImageTemplatePlatformImageSource

名字 描述 价值
提供 azure 库映像映像产品/服务。 字符串
planInfo 平台映像的购买计划的可选配置。 PlatformImagePurchasePlan
发行人 Azure 库映像中的映像发布服务器 字符串
sku Azure 库映像中的映像 SKU。 字符串
类型 指定要从其开始的源图像的类型。 “PlatformImage”(必需)
版本 Azure 库映像中的映像版本。 如果在此处指定了“latest”,则会在映像生成发生时评估版本,而不是提交模板时评估版本。 字符串

ImageTemplatePowerShellCustomizer

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

ImageTemplatePowerShellValidator

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

ImageTemplateProperties

名字 描述 价值
autoRun 指示是否在创建或更新模板时自动运行映像模板生成。 ImageTemplateAutoRun
buildTimeoutInMinutes 生成映像模板时等待的最大持续时间(包括所有自定义、优化、验证和分发)。 省略或指定 0 以使用默认值 (4 小时)。 int

约束:
最小值 = 0
最大值 = 960
自定义 指定用于描述映像的自定义步骤的属性,如图像源等 ImageTemplateCustomizer[]
分发 映像输出需要转到的分发目标。 ImageTemplateDistributor[] (必需)
errorHandling 生成失败时的错误处理选项 ImageTemplatePropertiesErrorHandling
managedResourceTags 将应用于服务创建的资源组和/或资源的标记。 ImageTemplatePropertiesManagedResourceTags
优化 指定要对图像执行的优化。 ImageTemplatePropertiesOptimize
指定用于描述源图像的属性。 ImageTemplateSource (必需)
stagingResourceGroup 与用于生成映像的映像模板相同的订阅中的暂存资源组 ID。 如果此字段为空,则会创建一个具有随机名称的资源组。 如果此字段中指定的资源组不存在,则会创建具有相同名称的资源组。 如果指定的资源组存在,则它必须是空的,并且与映像模板位于同一区域中。 如果此字段为空或指定的资源组不存在,则在模板删除期间将删除创建的资源组,但在模板删除期间将删除资源组中创建的资源,并且资源组本身将保留。 字符串
驗證 要对生成的映像执行的验证的配置选项和列表。 ImageTemplatePropertiesValidate
vmProfile 描述如何设置虚拟机以生成映像 ImageTemplateVmProfile

ImageTemplatePropertiesErrorHandling

名字 描述 价值
onCustomizerError 如果存在定制器错误,并且此字段设置为“清理”,则会清理生成 VM 和关联的网络资源。 这是默认行为。 如果存在定制器错误,并且此字段设置为“中止”,将保留生成 VM。 “abort”
“cleanup”
onValidationError 如果存在验证错误,并且此字段设置为“清理”,则会清理生成 VM 和关联的网络资源。 这是默认行为。 如果存在验证错误,并且此字段设置为“中止”,将保留生成 VM。 “abort”
“cleanup”

ImageTemplatePropertiesManagedResourceTags

名字 描述 价值

ImageTemplatePropertiesOptimize

名字 描述 价值
vmBoot 优化在映像上应用,以便更快地启动 VM。 ImageTemplatePropertiesOptimizeVmBoot

ImageTemplatePropertiesOptimizeVmBoot

名字 描述 价值
启用此字段将通过优化最终自定义映像输出来提高 VM 启动时间。 “Disabled”
“Enabled”

ImageTemplatePropertiesValidate

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

ImageTemplateRestartCustomizer

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

ImageTemplateSharedImageDistributor

名字 描述 价值
excludeFromLatest 指示是否应从最新版本中排除创建的映像版本的标志。 省略使用默认值(false)。 bool
galleryImageId Azure 计算库映像的资源 ID string (必需)
replicationRegions [已弃用]将映像复制到的区域列表。 仅当未指定 targetRegions 时,才能指定此列表。 此字段已弃用 - 请改用 targetRegions。 string[]
storageAccountType [已弃用]用于存储共享映像的存储帐户类型。 省略使用默认值(Standard_LRS)。 仅当指定 replicationRegions 时,才能指定此字段。 此字段已弃用 - 请改用 targetRegions。 “Premium_LRS”
“Standard_LRS”
“Standard_ZRS”
targetRegions 要将分布式映像版本复制到的目标区域。 此对象取代 replicationRegions,仅当未指定 replicationRegions 时才能指定。 TargetRegion[]
类型 分布类型。 “SharedImage”(必需)
versioning 介绍如何为分发生成新的 x.y.z 版本号。 DistributVersioner

ImageTemplateSharedImageVersionSource

名字 描述 价值
imageVersionId 映像版本的 ARM 资源 ID。 当映像版本名称为“latest”时,将在映像生成发生时评估版本。 string (必需)
类型 指定要从其开始的源图像的类型。 “SharedImageVersion”(必需)

ImageTemplateShellCustomizer

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

ImageTemplateShellValidator

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

ImageTemplateSource

名字 描述 价值
类型 对于 ImageTemplateManagedImageSource,请设置为“ManagedImage”。 设置为 ImageTemplatePlatformImageSource类型的“PlatformImage”。 对于 ImageTemplateSharedImageVersionSource,请设置为“SharedImageVersion”。 “ManagedImage”
“PlatformImage”
“SharedImageVersion”(必需)

ImageTemplateVhdDistributor

名字 描述 价值
类型 分布类型。 “VHD”(必需)
uri 分布式 VHD Blob 的可选 Azure 存储 URI。 省略使用默认的(空字符串),在这种情况下,VHD 将发布到暂存资源组中的存储帐户。 字符串

ImageTemplateVmProfile

名字 描述 价值
osDiskSizeGB OS 磁盘的大小(以 GB 为单位)。 省略或指定 0 以使用 Azure 的默认 OS 磁盘大小。 int

约束:
最小值 = 0
userAssignedIdentities 要在生成 VM 和验证 VM 上配置的用户分配托管标识的资源 ID 的可选数组。 这可能包括映像模板的标识。 string[]
vmSize 用于生成、自定义和捕获映像的虚拟机的大小。 省略或指定空字符串以使用默认值(第 1 代映像Standard_D1_v2,并为 Gen2 映像指定Standard_D2ds_v4)。 字符串
vnetConfig 用于部署生成 VM 和验证 VM 的虚拟网络的可选配置。 如果不需要使用任何特定的虚拟网络,则省略。 VirtualNetworkConfig

ImageTemplateWindowsUpdateCustomizer

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

约束:
最小值 = 0

Microsoft.VirtualMachineImages/imageTemplates

名字 描述 价值
apiVersion API 版本 '2024-02-01'
身份 映像模板的标识(如果已配置)。 ImageTemplateIdentity (必需)
位置 资源所在的地理位置 string (必需)
名字 资源名称 字符串

约束:
模式 = ^[A-Za-z0-9-_.]{1,64}$ (必需)
性能 映像模板的属性 ImageTemplateProperties
标签 资源标记 标记名称和值的字典。 请参阅模板 中的 标记
类型 资源类型 “Microsoft.VirtualMachineImages/imageTemplates”

PlatformImagePurchasePlan

名字 描述 价值
planName 购买计划的名称。 string (必需)
planProduct 购买计划的产品。 string (必需)
planPublisher 购买计划的发布者。 string (必需)

TargetRegion

名字 描述 价值
名字 区域的名称。 string (必需)
replicaCount 要在此区域中创建的映像版本的副本数。 省略使用默认值 (1)。 int

约束:
最小值 = 1
storageAccountType 指定要用于在此区域中存储映像的存储帐户类型。 省略使用默认值(Standard_LRS)。 “Premium_LRS”
“Standard_LRS”
“Standard_ZRS”

TrackedResourceTags

名字 描述 价值

UserAssignedIdentities

名字 描述 价值

UserAssignedIdentity

名字 描述 价值

VirtualNetworkConfig

名字 描述 价值
containerInstanceSubnetId 将为其部署 Azure 容器实例以供独立生成部署的预先存在的子网的资源 ID。 仅当同时指定 subnetId 并且必须与 subnetId中指定的子网位于同一虚拟网络中时,才能指定此字段。 字符串
proxyVmSize 用于将流量传递到生成 VM 和验证 VM 的代理虚拟机的大小。 如果未指定 containerInstanceSubnetId,则不能指定此项,因为在这种情况下没有部署代理虚拟机。 省略或指定空字符串以使用默认值(Standard_A1_v2)。 字符串
subnetId 将部署生成 VM 和验证 VM 的预先存在的子网的资源 ID 字符串

用法示例

Azure 快速入门模板

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

模板 描述
使用 Azure Windows 基线 Azure 映像生成器

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

部署到 Azure
此模板将按照 Dev Box 快速入门指南(/azure/dev-box/quickstart-create-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@2024-02-01"
  name = "string"
  identity = {
    type = "string"
    userAssignedIdentities = {
      {customized property} = {
      }
    }
  }
  location = "string"
  tags = {
    {customized property} = "string"
  }
  body = {
    properties = {
      autoRun = {
        state = "string"
      }
      buildTimeoutInMinutes = int
      customize = [
        {
          name = "string"
          type = "string"
          // For remaining properties, see ImageTemplateCustomizer objects
        }
      ]
      distribute = [
        {
          artifactTags = {
            {customized property} = "string"
          }
          runOutputName = "string"
          type = "string"
          // For remaining properties, see ImageTemplateDistributor objects
        }
      ]
      errorHandling = {
        onCustomizerError = "string"
        onValidationError = "string"
      }
      managedResourceTags = {
        {customized property} = "string"
      }
      optimize = {
        vmBoot = {
          state = "string"
        }
      }
      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 = {
          containerInstanceSubnetId = "string"
          proxyVmSize = "string"
          subnetId = "string"
        }
      }
    }
  }
}

ImageTemplateCustomizer 对象

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

对于 文件,请使用:

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

对于 PowerShell,请使用:

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

对于 Shell,请使用:

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

对于 WindowsRestart,请使用:

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

对于 windowsUpdate ,请使用:

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

DistributVersioner 对象

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

对于 最新,请使用:

{
  major = int
  scheme = "Latest"
}

对于 ,请使用:

{
  scheme = "Source"
}

ImageTemplateSource 对象

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

对于 managedImage,请使用:

{
  imageId = "string"
  type = "ManagedImage"
}

对于 PlatformImage,请使用:

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

对于 SharedImageVersion,请使用:

{
  imageVersionId = "string"
  type = "SharedImageVersion"
}

ImageTemplateInVMValidator 对象

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

对于 文件,请使用:

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

对于 PowerShell,请使用:

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

对于 Shell,请使用:

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

ImageTemplateDistributor 对象

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

对于 managedImage,请使用:

{
  imageId = "string"
  location = "string"
  type = "ManagedImage"
}

对于 SharedImage,请使用:

{
  excludeFromLatest = bool
  galleryImageId = "string"
  replicationRegions = [
    "string"
  ]
  storageAccountType = "string"
  targetRegions = [
    {
      name = "string"
      replicaCount = int
      storageAccountType = "string"
    }
  ]
  type = "SharedImage"
  versioning = {
    scheme = "string"
    // For remaining properties, see DistributeVersioner objects
  }
}

对于 VHD,请使用:

{
  type = "VHD"
  uri = "string"
}

属性值

DistributVersioner

名字 描述 价值
方案 对于 DistributVersionerLatest类型,设置为“Latest”。 设置为 DistributVersionerSource类型的“源”。 “Latest”
“Source”(必需)

DistributVersionerLatest

名字 描述 价值
主要 生成的版本号的主要版本。 根据此值作为主要版本的版本确定什么是“最新”。 -1 等效于将其保留为未设置。 int

约束:
最小值 = -1
方案 要使用的版本号方案。 “Latest”(必需)

DistributeVersionerSource

名字 描述 价值
方案 要使用的版本号方案。 “Source”(必需)

ImageTemplateAutoRun

名字 描述 价值
启用此字段将在创建或更新映像模板时触发自动生成。 “Disabled”
“Enabled”

ImageTemplateCustomizer

名字 描述 价值
名字 用于提供此自定义步骤的上下文的友好名称 字符串
类型 对于 imageTemplateFileCustomizer,请设置为“File”。 对于 imageTemplatePowerShellCustomizer,请设置为“PowerShell”。 对于 imageTemplateShellCustomizer,请设置为类型 “Shell”。 对于 imageTemplateRestartCustomizer,请设置为 “WindowsRestart”。 对于 imageTemplateWindowsUpdateCustomizer类型,设置为“WindowsUpdate”。 “File”
“PowerShell”
“Shell”
“WindowsRestart”
“WindowsUpdate”(必需)

ImageTemplateDistributor

名字 描述 价值
artifactTags 分发服务器创建/更新项目后,将应用于项目的标记。 ImageTemplateDistributorArtifactTags
runOutputName 要用于关联的 RunOutput 的名称。 字符串

约束:
模式 = ^[A-Za-z0-9-_.]{1,64}$ (必需)
类型 对于 ImageTemplateManagedImageDistributor类型,设置为“ManagedImage”。 对于 ImageTemplateSharedImageDistributor类型,设置为“SharedImage”。 对于 imageTemplateVhdDistributor ,请设置为“VHD”。 “ManagedImage”
“SharedImage”
“VHD”(必需)

ImageTemplateDistributorArtifactTags

名字 描述 价值

ImageTemplateFileCustomizer

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

ImageTemplateFileValidator

名字 描述 价值
目的地 文件(已创建嵌套目录结构)的绝对路径,该文件(来自 sourceUri)将上传到 VM 中 字符串
sha256Checksum 上述 sourceUri 字段中提供的文件的 SHA256 校验和 字符串
sourceUri 要上传到 VM 进行验证的文件的 URI。 它可以是 github 链接、Azure 存储 URI(已授权或 SAS),等等 字符串
类型 要在映像上使用的验证类型。 例如,“Shell”可以是 shell 验证 “File”(必需)

ImageTemplateIdentity

名字 描述 价值
类型 用于映像模板的标识类型。 类型“None”将从映像模板中删除任何标识。 “None”
“UserAssigned”
userAssignedIdentities 与资源关联的用户分配标识集。 userAssignedIdentities 字典密钥将为 ARM 资源 ID,格式为“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。 字典值可以是请求中的空对象({})。 UserAssignedIdentities

ImageTemplateInVMValidator

名字 描述 价值
名字 用于提供此验证步骤的上下文的友好名称 字符串
类型 对于 imageTemplateFileValidator,请设置为“File”。 对于 imageTemplatePowerShellValidator类型,设置为“PowerShell”。 对于 imageTemplateShellValidator类型,设置为“Shell”。 “File”
“PowerShell”
“Shell”(必需)

ImageTemplateManagedImageDistributor

名字 描述 价值
imageId 托管磁盘映像的资源 ID string (必需)
位置 映像的 Azure 位置应匹配(如果映像已存在) string (必需)
类型 分布类型。 “ManagedImage”(必需)

ImageTemplateManagedImageSource

名字 描述 价值
imageId 客户订阅中托管映像的 ARM 资源 ID string (必需)
类型 指定要从其开始的源图像的类型。 “ManagedImage”(必需)

ImageTemplatePlatformImageSource

名字 描述 价值
提供 azure 库映像映像产品/服务。 字符串
planInfo 平台映像的购买计划的可选配置。 PlatformImagePurchasePlan
发行人 Azure 库映像中的映像发布服务器 字符串
sku Azure 库映像中的映像 SKU。 字符串
类型 指定要从其开始的源图像的类型。 “PlatformImage”(必需)
版本 Azure 库映像中的映像版本。 如果在此处指定了“latest”,则会在映像生成发生时评估版本,而不是提交模板时评估版本。 字符串

ImageTemplatePowerShellCustomizer

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

ImageTemplatePowerShellValidator

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

ImageTemplateProperties

名字 描述 价值
autoRun 指示是否在创建或更新模板时自动运行映像模板生成。 ImageTemplateAutoRun
buildTimeoutInMinutes 生成映像模板时等待的最大持续时间(包括所有自定义、优化、验证和分发)。 省略或指定 0 以使用默认值 (4 小时)。 int

约束:
最小值 = 0
最大值 = 960
自定义 指定用于描述映像的自定义步骤的属性,如图像源等 ImageTemplateCustomizer[]
分发 映像输出需要转到的分发目标。 ImageTemplateDistributor[] (必需)
errorHandling 生成失败时的错误处理选项 ImageTemplatePropertiesErrorHandling
managedResourceTags 将应用于服务创建的资源组和/或资源的标记。 ImageTemplatePropertiesManagedResourceTags
优化 指定要对图像执行的优化。 ImageTemplatePropertiesOptimize
指定用于描述源图像的属性。 ImageTemplateSource (必需)
stagingResourceGroup 与用于生成映像的映像模板相同的订阅中的暂存资源组 ID。 如果此字段为空,则会创建一个具有随机名称的资源组。 如果此字段中指定的资源组不存在,则会创建具有相同名称的资源组。 如果指定的资源组存在,则它必须是空的,并且与映像模板位于同一区域中。 如果此字段为空或指定的资源组不存在,则在模板删除期间将删除创建的资源组,但在模板删除期间将删除资源组中创建的资源,并且资源组本身将保留。 字符串
驗證 要对生成的映像执行的验证的配置选项和列表。 ImageTemplatePropertiesValidate
vmProfile 描述如何设置虚拟机以生成映像 ImageTemplateVmProfile

ImageTemplatePropertiesErrorHandling

名字 描述 价值
onCustomizerError 如果存在定制器错误,并且此字段设置为“清理”,则会清理生成 VM 和关联的网络资源。 这是默认行为。 如果存在定制器错误,并且此字段设置为“中止”,将保留生成 VM。 “abort”
“cleanup”
onValidationError 如果存在验证错误,并且此字段设置为“清理”,则会清理生成 VM 和关联的网络资源。 这是默认行为。 如果存在验证错误,并且此字段设置为“中止”,将保留生成 VM。 “abort”
“cleanup”

ImageTemplatePropertiesManagedResourceTags

名字 描述 价值

ImageTemplatePropertiesOptimize

名字 描述 价值
vmBoot 优化在映像上应用,以便更快地启动 VM。 ImageTemplatePropertiesOptimizeVmBoot

ImageTemplatePropertiesOptimizeVmBoot

名字 描述 价值
启用此字段将通过优化最终自定义映像输出来提高 VM 启动时间。 “Disabled”
“Enabled”

ImageTemplatePropertiesValidate

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

ImageTemplateRestartCustomizer

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

ImageTemplateSharedImageDistributor

名字 描述 价值
excludeFromLatest 指示是否应从最新版本中排除创建的映像版本的标志。 省略使用默认值(false)。 bool
galleryImageId Azure 计算库映像的资源 ID string (必需)
replicationRegions [已弃用]将映像复制到的区域列表。 仅当未指定 targetRegions 时,才能指定此列表。 此字段已弃用 - 请改用 targetRegions。 string[]
storageAccountType [已弃用]用于存储共享映像的存储帐户类型。 省略使用默认值(Standard_LRS)。 仅当指定 replicationRegions 时,才能指定此字段。 此字段已弃用 - 请改用 targetRegions。 “Premium_LRS”
“Standard_LRS”
“Standard_ZRS”
targetRegions 要将分布式映像版本复制到的目标区域。 此对象取代 replicationRegions,仅当未指定 replicationRegions 时才能指定。 TargetRegion[]
类型 分布类型。 “SharedImage”(必需)
versioning 介绍如何为分发生成新的 x.y.z 版本号。 DistributVersioner

ImageTemplateSharedImageVersionSource

名字 描述 价值
imageVersionId 映像版本的 ARM 资源 ID。 当映像版本名称为“latest”时,将在映像生成发生时评估版本。 string (必需)
类型 指定要从其开始的源图像的类型。 “SharedImageVersion”(必需)

ImageTemplateShellCustomizer

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

ImageTemplateShellValidator

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

ImageTemplateSource

名字 描述 价值
类型 对于 ImageTemplateManagedImageSource,请设置为“ManagedImage”。 设置为 ImageTemplatePlatformImageSource类型的“PlatformImage”。 对于 ImageTemplateSharedImageVersionSource,请设置为“SharedImageVersion”。 “ManagedImage”
“PlatformImage”
“SharedImageVersion”(必需)

ImageTemplateVhdDistributor

名字 描述 价值
类型 分布类型。 “VHD”(必需)
uri 分布式 VHD Blob 的可选 Azure 存储 URI。 省略使用默认的(空字符串),在这种情况下,VHD 将发布到暂存资源组中的存储帐户。 字符串

ImageTemplateVmProfile

名字 描述 价值
osDiskSizeGB OS 磁盘的大小(以 GB 为单位)。 省略或指定 0 以使用 Azure 的默认 OS 磁盘大小。 int

约束:
最小值 = 0
userAssignedIdentities 要在生成 VM 和验证 VM 上配置的用户分配托管标识的资源 ID 的可选数组。 这可能包括映像模板的标识。 string[]
vmSize 用于生成、自定义和捕获映像的虚拟机的大小。 省略或指定空字符串以使用默认值(第 1 代映像Standard_D1_v2,并为 Gen2 映像指定Standard_D2ds_v4)。 字符串
vnetConfig 用于部署生成 VM 和验证 VM 的虚拟网络的可选配置。 如果不需要使用任何特定的虚拟网络,则省略。 VirtualNetworkConfig

ImageTemplateWindowsUpdateCustomizer

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

约束:
最小值 = 0

Microsoft.VirtualMachineImages/imageTemplates

名字 描述 价值
身份 映像模板的标识(如果已配置)。 ImageTemplateIdentity (必需)
位置 资源所在的地理位置 string (必需)
名字 资源名称 字符串

约束:
模式 = ^[A-Za-z0-9-_.]{1,64}$ (必需)
性能 映像模板的属性 ImageTemplateProperties
标签 资源标记 标记名称和值的字典。
类型 资源类型 “Microsoft.VirtualMachineImages/imageTemplates@2024-02-01”

PlatformImagePurchasePlan

名字 描述 价值
planName 购买计划的名称。 string (必需)
planProduct 购买计划的产品。 string (必需)
planPublisher 购买计划的发布者。 string (必需)

TargetRegion

名字 描述 价值
名字 区域的名称。 string (必需)
replicaCount 要在此区域中创建的映像版本的副本数。 省略使用默认值 (1)。 int

约束:
最小值 = 1
storageAccountType 指定要用于在此区域中存储映像的存储帐户类型。 省略使用默认值(Standard_LRS)。 “Premium_LRS”
“Standard_LRS”
“Standard_ZRS”

TrackedResourceTags

名字 描述 价值

UserAssignedIdentities

名字 描述 价值

UserAssignedIdentity

名字 描述 价值

VirtualNetworkConfig

名字 描述 价值
containerInstanceSubnetId 将为其部署 Azure 容器实例以供独立生成部署的预先存在的子网的资源 ID。 仅当同时指定 subnetId 并且必须与 subnetId中指定的子网位于同一虚拟网络中时,才能指定此字段。 字符串
proxyVmSize 用于将流量传递到生成 VM 和验证 VM 的代理虚拟机的大小。 如果未指定 containerInstanceSubnetId,则不能指定此项,因为在这种情况下没有部署代理虚拟机。 省略或指定空字符串以使用默认值(Standard_A1_v2)。 字符串
subnetId 将部署生成 VM 和验证 VM 的预先存在的子网的资源 ID 字符串