diff --git a/images/ubuntu/templates/ubuntu-22.04.pkr.hcl b/images/ubuntu/templates/ubuntu-22.04.pkr.hcl index eb96bd314..7f56a4d75 100644 --- a/images/ubuntu/templates/ubuntu-22.04.pkr.hcl +++ b/images/ubuntu/templates/ubuntu-22.04.pkr.hcl @@ -134,15 +134,61 @@ variable "vm_size" { default = "Standard_D4s_v4" } +variable "image_offer" { + type = string + default = "0001-com-ubuntu-server-jammy" +} + +variable "image_publisher" { + type = string + default = "canonical" +} + +variable "image_sku" { + type = string + default = "22_04-lts" +} + +variable "gallery_name" { + type = string + default = "${env("GALLERY_NAME")}" +} + +variable "gallery_resource_group_name" { + type = string + default = "${env("GALLERY_RESOURCE_GROUP_NAME")}" +} + +variable "gallery_image_name" { + type = string + default = "${env("GALLERY_IMAGE_NAME")}" +} + +variable "gallery_image_version" { + type = string + default = "${env("GALLERY_IMAGE_VERSION")}" +} + +variable "gallery_storage_account_type" { + type = string + default = "${env("GALLERY_STORAGE_ACCOUNT_TYPE")}" +} + +variable "use_azure_cli_auth" { + type = bool + default = false +} + source "azure-arm" "build_image" { allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}" build_resource_group_name = "${var.build_resource_group_name}" client_cert_path = "${var.client_cert_path}" client_id = "${var.client_id}" client_secret = "${var.client_secret}" - image_offer = "0001-com-ubuntu-server-jammy" - image_publisher = "canonical" - image_sku = "22_04-lts" + use_azure_cli_auth = var.use_azure_cli_auth + image_offer = "${var.image_offer}" + image_publisher = "${var.image_publisher}" + image_sku = "${var.image_sku}" location = "${var.location}" managed_image_name = "${local.managed_image_name}" managed_image_resource_group_name = "${var.managed_image_resource_group_name}" @@ -157,6 +203,15 @@ source "azure-arm" "build_image" { virtual_network_subnet_name = "${var.virtual_network_subnet_name}" vm_size = "${var.vm_size}" + shared_image_gallery_destination { + subscription = var.subscription_id + gallery_name = var.gallery_name + resource_group = var.gallery_resource_group_name + image_name = var.gallery_image_name + image_version = var.gallery_image_version + storage_account_type = var.gallery_storage_account_type + } + dynamic "azure_tag" { for_each = var.azure_tags content { diff --git a/images/ubuntu/templates/ubuntu-24.04.pkr.hcl b/images/ubuntu/templates/ubuntu-24.04.pkr.hcl index f67b7f33d..b3c1bc5ec 100644 --- a/images/ubuntu/templates/ubuntu-24.04.pkr.hcl +++ b/images/ubuntu/templates/ubuntu-24.04.pkr.hcl @@ -134,15 +134,61 @@ variable "vm_size" { default = "Standard_D4s_v4" } +variable "image_offer" { + type = string + default = "ubuntu-24_04-lts" +} + +variable "image_publisher" { + type = string + default = "canonical" +} + +variable "image_sku" { + type = string + default = "server-gen1" +} + +variable "gallery_name" { + type = string + default = "${env("GALLERY_NAME")}" +} + +variable "gallery_resource_group_name" { + type = string + default = "${env("GALLERY_RESOURCE_GROUP_NAME")}" +} + +variable "gallery_image_name" { + type = string + default = "${env("GALLERY_IMAGE_NAME")}" +} + +variable "gallery_image_version" { + type = string + default = "${env("GALLERY_IMAGE_VERSION")}" +} + +variable "gallery_storage_account_type" { + type = string + default = "${env("GALLERY_STORAGE_ACCOUNT_TYPE")}" +} + +variable "use_azure_cli_auth" { + type = bool + default = false +} + source "azure-arm" "build_image" { allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}" build_resource_group_name = "${var.build_resource_group_name}" client_cert_path = "${var.client_cert_path}" client_id = "${var.client_id}" client_secret = "${var.client_secret}" - image_offer = "ubuntu-24_04-lts" - image_publisher = "canonical" - image_sku = "server-gen1" + use_azure_cli_auth = var.use_azure_cli_auth + image_offer = "${var.image_offer}" + image_publisher = "${var.image_publisher}" + image_sku = "${var.image_sku}" location = "${var.location}" managed_image_name = "${local.managed_image_name}" managed_image_resource_group_name = "${var.managed_image_resource_group_name}" @@ -157,6 +203,15 @@ source "azure-arm" "build_image" { virtual_network_subnet_name = "${var.virtual_network_subnet_name}" vm_size = "${var.vm_size}" + shared_image_gallery_destination { + subscription = var.subscription_id + gallery_name = var.gallery_name + resource_group = var.gallery_resource_group_name + image_name = var.gallery_image_name + image_version = var.gallery_image_version + storage_account_type = var.gallery_storage_account_type + } + dynamic "azure_tag" { for_each = var.azure_tags content { diff --git a/images/windows/templates/windows-2019.pkr.hcl b/images/windows/templates/windows-2019.pkr.hcl index ac837c559..21d28bbda 100644 --- a/images/windows/templates/windows-2019.pkr.hcl +++ b/images/windows/templates/windows-2019.pkr.hcl @@ -144,16 +144,72 @@ variable "vm_size" { default = "Standard_F8s_v2" } +variable "image_offer" { + type = string + default = "WindowsServer" +} + +variable "image_publisher" { + type = string + default = "MicrosoftWindowsServer" +} + +variable "image_sku" { + type = string + default = "2019-Datacenter" +} + +variable "gallery_name" { + type = string + default = "${env("GALLERY_NAME")}" +} + +variable "gallery_resource_group_name" { + type = string + default = "${env("GALLERY_RESOURCE_GROUP_NAME")}" +} + +variable "gallery_image_name" { + type = string + default = "${env("GALLERY_IMAGE_NAME")}" +} + +variable "gallery_image_version" { + type = string + default = "${env("GALLERY_IMAGE_VERSION")}" +} + +variable "gallery_storage_account_type" { + type = string + default = "${env("GALLERY_STORAGE_ACCOUNT_TYPE")}" +} + +variable "build_key_vault_name" { + type = string + default = "${env("BUILD_KEY_VAULT_NAME")}" +} + +variable "build_key_vault_secret_name" { + type = string + default = "${env("BUILD_KEY_VAULT_SECRET_NAME")}" +} + +variable "use_azure_cli_auth" { + type = bool + default = false +} + source "azure-arm" "image" { allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}" build_resource_group_name = "${var.build_resource_group_name}" client_cert_path = "${var.client_cert_path}" client_id = "${var.client_id}" client_secret = "${var.client_secret}" + use_azure_cli_auth = var.use_azure_cli_auth communicator = "winrm" - image_offer = "WindowsServer" - image_publisher = "MicrosoftWindowsServer" - image_sku = "2019-Datacenter" + image_offer = "${var.image_offer}" + image_publisher = "${var.image_publisher}" + image_sku = "${var.image_sku}" location = "${var.location}" managed_image_name = "${local.managed_image_name}" managed_image_resource_group_name = "${var.managed_image_resource_group_name}" @@ -172,6 +228,18 @@ source "azure-arm" "image" { winrm_insecure = "true" winrm_use_ssl = "true" winrm_username = "packer" + winrm_expiration_time = "1440h" + build_key_vault_name = var.build_key_vault_name + build_key_vault_secret_name = var.build_key_vault_secret_name + + shared_image_gallery_destination { + subscription = var.subscription_id + gallery_name = var.gallery_name + resource_group = var.gallery_resource_group_name + image_name = var.gallery_image_name + image_version = var.gallery_image_version + storage_account_type = var.gallery_storage_account_type + } dynamic "azure_tag" { for_each = var.azure_tags diff --git a/images/windows/templates/windows-2022.pkr.hcl b/images/windows/templates/windows-2022.pkr.hcl index 98c6034cf..84d0f7190 100644 --- a/images/windows/templates/windows-2022.pkr.hcl +++ b/images/windows/templates/windows-2022.pkr.hcl @@ -144,16 +144,72 @@ variable "vm_size" { default = "Standard_F8s_v2" } +variable "image_offer" { + type = string + default = "WindowsServer" +} + +variable "image_publisher" { + type = string + default = "MicrosoftWindowsServer" +} + +variable "image_sku" { + type = string + default = "2022-Datacenter" +} + +variable "gallery_name" { + type = string + default = "${env("GALLERY_NAME")}" +} + +variable "gallery_resource_group_name" { + type = string + default = "${env("GALLERY_RESOURCE_GROUP_NAME")}" +} + +variable "gallery_image_name" { + type = string + default = "${env("GALLERY_IMAGE_NAME")}" +} + +variable "gallery_image_version" { + type = string + default = "${env("GALLERY_IMAGE_VERSION")}" +} + +variable "gallery_storage_account_type" { + type = string + default = "${env("GALLERY_STORAGE_ACCOUNT_TYPE")}" +} + +variable "build_key_vault_name" { + type = string + default = "${env("BUILD_KEY_VAULT_NAME")}" +} + +variable "build_key_vault_secret_name" { + type = string + default = "${env("BUILD_KEY_VAULT_SECRET_NAME")}" +} + +variable "use_azure_cli_auth" { + type = bool + default = false +} + source "azure-arm" "image" { allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}" build_resource_group_name = "${var.build_resource_group_name}" client_cert_path = "${var.client_cert_path}" client_id = "${var.client_id}" client_secret = "${var.client_secret}" + use_azure_cli_auth = var.use_azure_cli_auth communicator = "winrm" - image_offer = "WindowsServer" - image_publisher = "MicrosoftWindowsServer" - image_sku = "2022-Datacenter" + image_offer = "${var.image_offer}" + image_publisher = "${var.image_publisher}" + image_sku = "${var.image_sku}" location = "${var.location}" managed_image_name = "${local.managed_image_name}" managed_image_resource_group_name = "${var.managed_image_resource_group_name}" @@ -172,6 +228,18 @@ source "azure-arm" "image" { winrm_insecure = "true" winrm_use_ssl = "true" winrm_username = "packer" + winrm_expiration_time = "1440h" + build_key_vault_name = var.build_key_vault_name + build_key_vault_secret_name = var.build_key_vault_secret_name + + shared_image_gallery_destination { + subscription = var.subscription_id + gallery_name = var.gallery_name + resource_group = var.gallery_resource_group_name + image_name = var.gallery_image_name + image_version = var.gallery_image_version + storage_account_type = var.gallery_storage_account_type + } dynamic "azure_tag" { for_each = var.azure_tags diff --git a/images/windows/templates/windows-2025.pkr.hcl b/images/windows/templates/windows-2025.pkr.hcl index 72eda50e2..c7248c951 100644 --- a/images/windows/templates/windows-2025.pkr.hcl +++ b/images/windows/templates/windows-2025.pkr.hcl @@ -144,16 +144,72 @@ variable "vm_size" { default = "Standard_F8s_v2" } +variable "image_offer" { + type = string + default = "WindowsServer" +} + +variable "image_publisher" { + type = string + default = "MicrosoftWindowsServer" +} + +variable "image_sku" { + type = string + default = "2025-Datacenter" +} + +variable "gallery_name" { + type = string + default = "${env("GALLERY_NAME")}" +} + +variable "gallery_resource_group_name" { + type = string + default = "${env("GALLERY_RESOURCE_GROUP_NAME")}" +} + +variable "gallery_image_name" { + type = string + default = "${env("GALLERY_IMAGE_NAME")}" +} + +variable "gallery_image_version" { + type = string + default = "${env("GALLERY_IMAGE_VERSION")}" +} + +variable "gallery_storage_account_type" { + type = string + default = "${env("GALLERY_STORAGE_ACCOUNT_TYPE")}" +} + +variable "build_key_vault_name" { + type = string + default = "${env("BUILD_KEY_VAULT_NAME")}" +} + +variable "build_key_vault_secret_name" { + type = string + default = "${env("BUILD_KEY_VAULT_SECRET_NAME")}" +} + +variable "use_azure_cli_auth" { + type = bool + default = false +} + source "azure-arm" "image" { allowed_inbound_ip_addresses = "${var.allowed_inbound_ip_addresses}" build_resource_group_name = "${var.build_resource_group_name}" client_cert_path = "${var.client_cert_path}" client_id = "${var.client_id}" client_secret = "${var.client_secret}" + use_azure_cli_auth = var.use_azure_cli_auth communicator = "winrm" - image_offer = "WindowsServer" - image_publisher = "MicrosoftWindowsServer" - image_sku = "2025-Datacenter" + image_offer = "${var.image_offer}" + image_publisher = "${var.image_publisher}" + image_sku = "${var.image_sku}" location = "${var.location}" managed_image_name = "${local.managed_image_name}" managed_image_resource_group_name = "${var.managed_image_resource_group_name}" @@ -172,6 +228,18 @@ source "azure-arm" "image" { winrm_insecure = "true" winrm_use_ssl = "true" winrm_username = "packer" + winrm_expiration_time = "1440h" + build_key_vault_name = var.build_key_vault_name + build_key_vault_secret_name = var.build_key_vault_secret_name + + shared_image_gallery_destination { + subscription = var.subscription_id + gallery_name = var.gallery_name + resource_group = var.gallery_resource_group_name + image_name = var.gallery_image_name + image_version = var.gallery_image_version + storage_account_type = var.gallery_storage_account_type + } dynamic "azure_tag" { for_each = var.azure_tags