From cf8a85acd0a50a77fc7c61f865be35ff4d059d60 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 18 Dec 2023 16:08:41 -0800 Subject: [PATCH 1/2] azurerm_*_virtual_machine - additional_capabilities.0.ultra_ssd_enabled can now be upadded during update --- .../compute/linux_virtual_machine_resource.go | 3 +- ...nux_virtual_machine_resource_other_test.go | 57 +++++++++++++++++++ .../windows_virtual_machine_resource.go | 3 +- ...ows_virtual_machine_resource_other_test.go | 52 +++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) diff --git a/internal/services/compute/linux_virtual_machine_resource.go b/internal/services/compute/linux_virtual_machine_resource.go index 685f0629efcb..0dcecb543d9a 100644 --- a/internal/services/compute/linux_virtual_machine_resource.go +++ b/internal/services/compute/linux_virtual_machine_resource.go @@ -1386,7 +1386,8 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface if d.HasChange("additional_capabilities") { shouldUpdate = true - if d.HasChange("additional_capabilities.0.ultra_ssd_enabled") { + n, _ := d.GetChange("additional_capabilities") + if len(n.([]interface{})) == 0 || d.HasChange("additional_capabilities.0.ultra_ssd_enabled") { shouldShutDown = true shouldDeallocate = true } diff --git a/internal/services/compute/linux_virtual_machine_resource_other_test.go b/internal/services/compute/linux_virtual_machine_resource_other_test.go index 8711a0cb5256..0f0a1810f43d 100644 --- a/internal/services/compute/linux_virtual_machine_resource_other_test.go +++ b/internal/services/compute/linux_virtual_machine_resource_other_test.go @@ -624,6 +624,28 @@ func TestAccLinuxVirtualMachine_otherUltraSsdUpdated(t *testing.T) { }) } +func u(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") + r := LinuxVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.otherUltraSsdEmpty(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.otherUltraSsd(data, false), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("additional_capabilities.0.ultra_ssd_enabled").HasValue("false"), + ), + }, + }) +} + func TestAccLinuxVirtualMachine_otherEncryptionAtHostEnabled(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") r := LinuxVirtualMachineResource{} @@ -2486,6 +2508,41 @@ resource "azurerm_linux_virtual_machine" "test" { `, r.template(data), data.RandomInteger, ultraSsdEnabled) } +func (r LinuxVirtualMachineResource) otherUltraSsdEmpty(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_D2s_v3" + admin_username = "adminuser" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + zone = 1 + + admin_ssh_key { + username = "adminuser" + public_key = local.first_public_key + } + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "Canonical" + offer = "0001-com-ubuntu-server-jammy" + sku = "22_04-lts" + version = "latest" + } +} +`, r.template(data), data.RandomInteger) +} + func (r LinuxVirtualMachineResource) otherEncryptionAtHostEnabled(data acceptance.TestData, enabled bool) string { return fmt.Sprintf(` %s diff --git a/internal/services/compute/windows_virtual_machine_resource.go b/internal/services/compute/windows_virtual_machine_resource.go index c21bf7a6a8e6..f422006fb5c1 100644 --- a/internal/services/compute/windows_virtual_machine_resource.go +++ b/internal/services/compute/windows_virtual_machine_resource.go @@ -1434,7 +1434,8 @@ func resourceWindowsVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interfa if d.HasChange("additional_capabilities") { shouldUpdate = true - if d.HasChange("additional_capabilities.0.ultra_ssd_enabled") { + n, _ := d.GetChange("additional_capabilities") + if len(n.([]interface{})) == 0 || d.HasChange("additional_capabilities.0.ultra_ssd_enabled") { shouldShutDown = true shouldDeallocate = true } diff --git a/internal/services/compute/windows_virtual_machine_resource_other_test.go b/internal/services/compute/windows_virtual_machine_resource_other_test.go index 08a3397c0737..ac3b12fe5526 100644 --- a/internal/services/compute/windows_virtual_machine_resource_other_test.go +++ b/internal/services/compute/windows_virtual_machine_resource_other_test.go @@ -841,7 +841,28 @@ func TestAccWindowsVirtualMachine_otherUltraSsdUpdated(t *testing.T) { check.That(data.ResourceName).Key("additional_capabilities.0.ultra_ssd_enabled").HasValue("true"), ), }, + }) +} + +func TestAccWindowsVirtualMachine_otherUltraSsdEmptyToUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") + r := WindowsVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.otherUltraSsdEmpty(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, data.ImportStep("admin_password"), + { + Config: r.otherUltraSsd(data, false), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("additional_capabilities.0.ultra_ssd_enabled").HasValue("false"), + ), + }, }) } @@ -2887,6 +2908,37 @@ resource "azurerm_windows_virtual_machine" "test" { `, r.template(data), ultraSsdEnabled) } +func (r WindowsVirtualMachineResource) otherUltraSsdEmpty(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_windows_virtual_machine" "test" { + name = local.vm_name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_D2s_v3" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + zone = 1 + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } +} +`, r.template(data)) +} + func (r WindowsVirtualMachineResource) otherWinRMHTTP(data acceptance.TestData) string { return fmt.Sprintf(` %s From f47c666f57da9a453500cc1cdc56e329e54076e2 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 18 Dec 2023 16:19:44 -0800 Subject: [PATCH 2/2] lint --- .../compute/linux_virtual_machine_resource_other_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/compute/linux_virtual_machine_resource_other_test.go b/internal/services/compute/linux_virtual_machine_resource_other_test.go index 0f0a1810f43d..0839a898538d 100644 --- a/internal/services/compute/linux_virtual_machine_resource_other_test.go +++ b/internal/services/compute/linux_virtual_machine_resource_other_test.go @@ -624,7 +624,7 @@ func TestAccLinuxVirtualMachine_otherUltraSsdUpdated(t *testing.T) { }) } -func u(t *testing.T) { +func TestAccLinuxVirtualMachine_otherUltraSsdEmptyToUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") r := LinuxVirtualMachineResource{}