From d1ad36fa2847ed9b4375daa35f8ae62736c13781 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Thu, 12 Dec 2024 16:01:49 +0800 Subject: [PATCH] `azurerm_windows_virtual_machine` - Support Hotpatch for Windows Server 2025 (#28160) * Hotpatch support for Windows Server 2025 * fix comment --- ...estrated_virtual_machine_scale_set_resource.go | 2 +- internal/services/compute/shared_schema.go | 15 ++++++++++++++- .../compute/windows_virtual_machine_resource.go | 5 +++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go index ec21373326b1..ad38287dab93 100644 --- a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go @@ -553,7 +553,7 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, } if hotpatchingEnabled { - return fmt.Errorf("'hotpatching_enabled' field is not supported unless you are using one of the following hotpatching enable images, '2022-datacenter-azure-edition', '2022-datacenter-azure-edition-core-smalldisk', '2022-datacenter-azure-edition-hotpatch' or '2022-datacenter-azure-edition-hotpatch-smalldisk'") + return fmt.Errorf("'hotpatching_enabled' field is not supported unless you are using one of the following hotpatching enable images, '2022-datacenter-azure-edition', '2022-datacenter-azure-edition-core-smalldisk', '2022-datacenter-azure-edition-hotpatch', '2022-datacenter-azure-edition-hotpatch-smalldisk', '2025-datacenter-azure-edition', '2025-datacenter-azure-edition-smalldisk', '2025-datacenter-azure-edition-core' or '2025-datacenter-azure-edition-core-smalldisk'") } } } diff --git a/internal/services/compute/shared_schema.go b/internal/services/compute/shared_schema.go index 242b26b45dbe..2f1ca115a12a 100644 --- a/internal/services/compute/shared_schema.go +++ b/internal/services/compute/shared_schema.go @@ -4,6 +4,8 @@ package compute import ( + "slices" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" @@ -641,7 +643,18 @@ func isValidHotPatchSourceImageReference(referenceInput []interface{}, imageId s offer := raw["offer"].(string) sku := raw["sku"].(string) - if pub == "MicrosoftWindowsServer" && offer == "WindowsServer" && (sku == "2022-datacenter-azure-edition-core" || sku == "2022-datacenter-azure-edition-core-smalldisk" || sku == "2022-datacenter-azure-edition-hotpatch" || sku == "2022-datacenter-azure-edition-hotpatch-smalldisk") { + supportedSkus := []string{ + "2022-datacenter-azure-edition-core", + "2022-datacenter-azure-edition-core-smalldisk", + "2022-datacenter-azure-edition-hotpatch", + "2022-datacenter-azure-edition-hotpatch-smalldisk", + "2025-datacenter-azure-edition", + "2025-datacenter-azure-edition-smalldisk", + "2025-datacenter-azure-edition-core", + "2025-datacenter-azure-edition-core-smalldisk", + } + + if pub == "MicrosoftWindowsServer" && offer == "WindowsServer" && slices.Contains(supportedSkus, sku) { return true } diff --git a/internal/services/compute/windows_virtual_machine_resource.go b/internal/services/compute/windows_virtual_machine_resource.go index 022649757924..ff56d4122e52 100644 --- a/internal/services/compute/windows_virtual_machine_resource.go +++ b/internal/services/compute/windows_virtual_machine_resource.go @@ -598,7 +598,8 @@ func resourceWindowsVirtualMachineCreate(d *pluginsdk.ResourceData, meta interfa // hot patching can only be enabled if the patch_mode is set to "AutomaticByPlatform" // and if the image reference is using one of the following skus: - // 2022-datacenter-azure-edition-core or 2022-datacenter-azure-edition-core-smalldisk + // 2022-datacenter-azure-edition-core, 2022-datacenter-azure-edition-core-smalldisk, 2022-datacenter-azure-edition-hotpatch, 2022-datacenter-azure-edition-hotpatch-smalldisk, + // 2025-datacenter-azure-edition, 2025-datacenter-azure-edition-smalldisk, 2025-datacenter-azure-edition-core, 2025-datacenter-azure-edition-core-smalldisk if hotPatch { if patchMode != string(virtualmachines.WindowsVMGuestPatchModeAutomaticByPlatform) { return fmt.Errorf("%q cannot be set to %q when %q is set to %q", "hotpatching_enabled", "true", "patch_mode", patchMode) @@ -613,7 +614,7 @@ func resourceWindowsVirtualMachineCreate(d *pluginsdk.ResourceData, meta interfa return fmt.Errorf("the %q field is not supported if referencing the image via the %q field", "hotpatching_enabled", "source_image_id") } - return fmt.Errorf("%q is currently only supported on %q, %q, %q or %q image reference skus", "hotpatching_enabled", "2022-datacenter-azure-edition-core", "2022-datacenter-azure-edition-core-smalldisk", "2022-datacenter-azure-edition-hotpatch", "2022-datacenter-azure-edition-hotpatch-smalldisk") + return fmt.Errorf("%q is currently only supported on %q, %q, %q, %q, %q, %q, %q or %q image reference skus", "hotpatching_enabled", "2022-datacenter-azure-edition-core", "2022-datacenter-azure-edition-core-smalldisk", "2022-datacenter-azure-edition-hotpatch", "2022-datacenter-azure-edition-hotpatch-smalldisk", "2025-datacenter-azure-edition", "2025-datacenter-azure-edition-smalldisk", "2025-datacenter-azure-edition-core", "2025-datacenter-azure-edition-core-smalldisk") } }