You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure中基于私有Packer镜像创建新镜像的配置方法问询

How to Reference an Azure Private Image in Packer Instead of Marketplace Images

Great question! When working with Azure private images in Packer, you won't use the image_publisher, image_offer, or image_sku fields—those are exclusively for targeting public marketplace images. Instead, you'll use one of two straightforward approaches to point directly to your existing private image.

Option 1: Use the Private Image's Resource ID

You can reference your private image by its full Azure resource ID. This is the most explicit method, especially if you're working across multiple subscriptions or resource groups.

Here's an example HCL configuration snippet:

source "azure-arm" "private_image_base" {
  # Required Azure authentication fields (client_id, client_secret, tenant_id, subscription_id)
  os_type                = "Linux" # Swap to "Windows" if your private image uses Windows
  location               = "eastus"

  # Reference the private image via its resource ID
  image_id               = "/subscriptions/your-subscription-id/resourceGroups/your-source-rg/providers/Microsoft.Compute/images/your-private-image-name"

  # Configuration for the new image you're building
  managed_image_resource_group_name = "your-output-rg"
  managed_image_name                = "new-custom-packer-image"
}

build {
  sources = ["source.azure-arm.private_image_base"]
  # Add your provisioners (shell scripts, Ansible playbooks, etc.) here
}

Option 2: Use Resource Group and Image Name

If your private image is in the same subscription as your Packer build, you can simplify the reference by specifying just the resource group name and the image name:

source "azure-arm" "private_image_base" {
  # Required Azure authentication fields
  os_type                = "Linux"
  location               = "eastus"

  # Reference the private image by resource group and name
  managed_image_resource_group_name = "your-source-rg"
  managed_image_name                = "your-private-image-name"

  # Configuration for the output image
  managed_image_resource_group_name = "your-output-rg"
  managed_image_name                = "new-custom-packer-image"
}

Key Notes:

  • Choose one option only: Don't include both image_id and the managed_image_resource_group_name/managed_image_name pair—pick the method that fits your workflow best.
  • Permissions matter: Ensure the service principal or identity you're using for Packer has at least the Compute Image Reader role on the resource group containing your private image. Without this, Packer won't be able to access the base image.
  • Skip marketplace fields: Remove any image_publisher, image_offer, or image_sku lines from your configuration—they'll cause Packer to look for a public marketplace image, which will fail since you're targeting a private one.

内容的提问来源于stack exchange,提问作者James Liu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:06:08