From 79625a36399384c33fedb4b7974be93061937317 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Thu, 27 Nov 2025 15:36:32 +0100 Subject: [PATCH] Refactor Source image SKUs in packer templates (#13364) * [ubuntu] Refactor image properties mapping to use source_image_marketplace_sku * Refactor Ubuntu and Windows image properties to simplify disk size handling and update marketplace SKU mappings * Refactor disk size handling to use coalesce for improved flexibility --- images/ubuntu/templates/locals.ubuntu.pkr.hcl | 15 ++++++------- images/ubuntu/templates/source.ubuntu.pkr.hcl | 8 +++---- .../windows/templates/locals.windows.pkr.hcl | 21 +++++++------------ .../windows/templates/source.windows.pkr.hcl | 8 +++---- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/images/ubuntu/templates/locals.ubuntu.pkr.hcl b/images/ubuntu/templates/locals.ubuntu.pkr.hcl index fe9b189ab..469493d3f 100644 --- a/images/ubuntu/templates/locals.ubuntu.pkr.hcl +++ b/images/ubuntu/templates/locals.ubuntu.pkr.hcl @@ -1,18 +1,15 @@ locals { image_properties_map = { "ubuntu22" = { - publisher = "canonical" - offer = "0001-com-ubuntu-server-jammy" - sku = "22_04-lts" - os_disk_size_gb = coalesce(var.os_disk_size_gb, 75) + source_image_marketplace_sku = "canonical:0001-com-ubuntu-server-jammy:22_04-lts" + os_disk_size_gb = 75 }, "ubuntu24" = { - publisher = "canonical" - offer = "ubuntu-24_04-lts" - sku = "server-gen1" - os_disk_size_gb = coalesce(var.os_disk_size_gb, 75) + source_image_marketplace_sku = "canonical:ubuntu-24_04-lts:server-gen1" + os_disk_size_gb = 75 } } - image_properties = local.image_properties_map[var.image_os] + source_image_marketplace_sku = local.image_properties_map[var.image_os].source_image_marketplace_sku + os_disk_size_gb = coalesce(var.os_disk_size_gb, local.image_properties_map[var.image_os].os_disk_size_gb) } diff --git a/images/ubuntu/templates/source.ubuntu.pkr.hcl b/images/ubuntu/templates/source.ubuntu.pkr.hcl index e29dacccd..babc3cb5f 100644 --- a/images/ubuntu/templates/source.ubuntu.pkr.hcl +++ b/images/ubuntu/templates/source.ubuntu.pkr.hcl @@ -11,15 +11,15 @@ source "azure-arm" "image" { allowed_inbound_ip_addresses = var.allowed_inbound_ip_addresses build_resource_group_name = var.build_resource_group_name - image_offer = local.image_properties.offer - image_publisher = local.image_properties.publisher - image_sku = local.image_properties.sku + image_publisher = split(":", local.source_image_marketplace_sku)[0] + image_offer = split(":", local.source_image_marketplace_sku)[1] + image_sku = split(":", local.source_image_marketplace_sku)[2] image_version = var.source_image_version location = var.location managed_image_name = var.managed_image_name managed_image_resource_group_name = var.managed_image_resource_group_name managed_image_storage_account_type = var.managed_image_storage_account_type - os_disk_size_gb = local.image_properties.os_disk_size_gb + os_disk_size_gb = local.os_disk_size_gb os_type = var.image_os_type private_virtual_network_with_public_ip = var.private_virtual_network_with_public_ip ssh_clear_authorized_keys = var.ssh_clear_authorized_keys diff --git a/images/windows/templates/locals.windows.pkr.hcl b/images/windows/templates/locals.windows.pkr.hcl index d03ab4524..976b4ffb0 100644 --- a/images/windows/templates/locals.windows.pkr.hcl +++ b/images/windows/templates/locals.windows.pkr.hcl @@ -1,24 +1,19 @@ locals { image_properties_map = { "win19" = { - publisher = "MicrosoftWindowsServer" - offer = "WindowsServer" - sku = "2019-Datacenter" - os_disk_size_gb = coalesce(var.os_disk_size_gb, 256) + source_image_marketplace_sku = "MicrosoftWindowsServer:WindowsServer:2019-Datacenter" + os_disk_size_gb = 256 }, "win22" = { - publisher = "MicrosoftWindowsServer" - offer = "WindowsServer" - sku = "2022-Datacenter" - os_disk_size_gb = coalesce(var.os_disk_size_gb, 256) + source_image_marketplace_sku = "MicrosoftWindowsServer:WindowsServer:2022-Datacenter" + os_disk_size_gb = 256 }, "win25" = { - publisher = "MicrosoftWindowsServer" - offer = "WindowsServer" - sku = "2025-Datacenter" - os_disk_size_gb = coalesce(var.os_disk_size_gb, 150) + source_image_marketplace_sku = "MicrosoftWindowsServer:WindowsServer:2025-Datacenter" + os_disk_size_gb = 150 } } - image_properties = local.image_properties_map[var.image_os] + source_image_marketplace_sku = local.image_properties_map[var.image_os].source_image_marketplace_sku + os_disk_size_gb = coalesce(var.os_disk_size_gb, local.image_properties_map[var.image_os].os_disk_size_gb) } diff --git a/images/windows/templates/source.windows.pkr.hcl b/images/windows/templates/source.windows.pkr.hcl index 36aac4035..8b407810d 100644 --- a/images/windows/templates/source.windows.pkr.hcl +++ b/images/windows/templates/source.windows.pkr.hcl @@ -14,15 +14,15 @@ source "azure-arm" "image" { build_key_vault_secret_name = var.build_key_vault_secret_name build_resource_group_name = var.build_resource_group_name communicator = "winrm" - image_offer = local.image_properties.offer - image_publisher = local.image_properties.publisher - image_sku = local.image_properties.sku + image_publisher = split(":", local.source_image_marketplace_sku)[0] + image_offer = split(":", local.source_image_marketplace_sku)[1] + image_sku = split(":", local.source_image_marketplace_sku)[2] image_version = var.source_image_version location = var.location managed_image_name = var.managed_image_name managed_image_resource_group_name = var.managed_image_resource_group_name managed_image_storage_account_type = var.managed_image_storage_account_type - os_disk_size_gb = local.image_properties.os_disk_size_gb + os_disk_size_gb = local.os_disk_size_gb os_type = var.image_os_type private_virtual_network_with_public_ip = var.private_virtual_network_with_public_ip temp_resource_group_name = var.temp_resource_group_name