= 1.0.0" source = "github.com/hashicorp/azure" } } } source "azure-arm" "example" { managed_image_name" /> = 1.0.0" source = "github.com/hashicorp/azure" } } } source "azure-arm" "example" { managed_image_name" /> = 1.0.0" source = "github.com/hashicorp/azure" } } } source "azure-arm" "example" { managed_image_name"/>

Providing the source image details in the HCL file for packer to automate the image process in the Azure

38 Views Asked by At

packer 
  required_plugins {
    azure = {
      version = ">= 1.0.0"
      source  = "github.com/hashicorp/azure"
    }
  }
}

source "azure-arm" "example" {
  managed_image_name                 = "test-ubuntu-20.04img-${formatdate("DD-MMM-YYYY-hh-mm-ss", timestamp())}"  managed_image_resource_group_name  = var.gallery_resource_group
  managed_image_storage_account_type = "Standard_LRS"
  location                           = var.location

  # Using Azure CLI for authentication
  use_azure_cli_auth = true

  image_offer     = "0001-com-ubuntu-server-focal"
  image_publisher = "Canonical"
  image_sku       = "20_04-lts-gen2"

  os_type         = "Linux"
  vm_size         = "Standard_B4ms"
  os_disk_size_gb = 64

  shared_image_gallery_destination {
    resource_group       = var.gallery_resource_group
    gallery_name         = var.gallery_name
    image_name           = "test-ubuntu-20.04"
    image_version        = "1.0.0"
    replication_regions  = ["uaenorth"]
    storage_account_type = "Standard_LRS"
  }
}

build {
  sources = [
    "source.azure-arm.example"
  ]

  provisioner "shell" {
    execute_command = "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}"
    script          = "install.sh"
  }

I am trying to create custom image using packer using above HCL file. and I have compute image gallery in azure which you can see below from azure I want to create 1.0.2 from 1.0.0

But I have not found option to provide source image details where exactly I should give those details above in HCL file?

enter image description here

1

There are 1 best solutions below

0
Marcin Słowikowski On

I recommend creating a new version from the clean base image, adding a modification in the build block and changing the version. This allows you to see the entire image preparation process in the Packer file.

But if you want you can define shared_image_gallery in source block to use image from Azure Compute Gallery as source image

shared_image_gallery {
    subscription = "00000000-0000-0000-0000-00000000000"
    resource_group = var.gallery_resource_group
    gallery_name = var.gallery_name
    image_name = "test-ubuntu-20.04"
    image_version = "1.0.0"
}

shared_image_gallery_destination {
    resource_group       = var.gallery_resource_group
    gallery_name         = var.gallery_name
    image_name           = "test-ubuntu-20.04"
    image_version        = "1.0.2"
    replication_regions  = ["uaenorth"]
    storage_account_type = "Standard_LRS"
}

https://developer.hashicorp.com/packer/integrations/hashicorp/azure/latest/components/builder/arm#shared-image-gallery