From a239fbcd3149a43dba6b16875189f64152d001a9 Mon Sep 17 00:00:00 2001 From: Allen Humphreys Date: Mon, 13 Jun 2022 10:23:27 -0400 Subject: [PATCH 1/3] Allow Delete eviction policy on Azure VMs --- internal/services/compute/linux_virtual_machine_resource.go | 2 +- internal/services/compute/windows_virtual_machine_resource.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/compute/linux_virtual_machine_resource.go b/internal/services/compute/linux_virtual_machine_resource.go index b8494189274f..5706088b1081 100644 --- a/internal/services/compute/linux_virtual_machine_resource.go +++ b/internal/services/compute/linux_virtual_machine_resource.go @@ -180,8 +180,8 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource { Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - // NOTE: whilst Delete is an option here, it's only applicable for VMSS string(compute.VirtualMachineEvictionPolicyTypesDeallocate), + string(compute.VirtualMachineEvictionPolicyTypesDelete), }, false), }, diff --git a/internal/services/compute/windows_virtual_machine_resource.go b/internal/services/compute/windows_virtual_machine_resource.go index 808b5f82876d..3822b62605f1 100644 --- a/internal/services/compute/windows_virtual_machine_resource.go +++ b/internal/services/compute/windows_virtual_machine_resource.go @@ -181,8 +181,8 @@ func resourceWindowsVirtualMachine() *pluginsdk.Resource { Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - // NOTE: whilst Delete is an option here, it's only applicable for VMSS string(compute.VirtualMachineEvictionPolicyTypesDeallocate), + string(compute.VirtualMachineEvictionPolicyTypesDelete), }, false), }, From 665aec363a4e9f81f9e45696b32b71f34c654517 Mon Sep 17 00:00:00 2001 From: Allen Humphreys Date: Tue, 14 Jun 2022 10:41:21 -0400 Subject: [PATCH 2/3] Update and align VM documentation on evicition_policy --- website/docs/r/linux_virtual_machine.html.markdown | 2 +- website/docs/r/linux_virtual_machine_scale_set.html.markdown | 2 +- website/docs/r/windows_virtual_machine.html.markdown | 2 +- website/docs/r/windows_virtual_machine_scale_set.html.markdown | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/r/linux_virtual_machine.html.markdown b/website/docs/r/linux_virtual_machine.html.markdown index ae07bfa0459c..fcc6029717b3 100644 --- a/website/docs/r/linux_virtual_machine.html.markdown +++ b/website/docs/r/linux_virtual_machine.html.markdown @@ -144,7 +144,7 @@ The following arguments are supported: * `encryption_at_host_enabled` - (Optional) Should all of the disks (including the temp disk) attached to this Virtual Machine be encrypted by enabling Encryption at Host? -* `eviction_policy` - (Optional) Specifies what should happen when the Virtual Machine is evicted for price reasons when using a Spot instance. At this time the only supported value is `Deallocate`. Changing this forces a new resource to be created. +* `eviction_policy` - (Optional) Specifies what should happen when the Virtual Machine is evicted for price reasons when using a Spot instance. Possible values are `Deallocate` and `Delete`. Changing this forces a new resource to be created. -> **NOTE:** This can only be configured when `priority` is set to `Spot`. diff --git a/website/docs/r/linux_virtual_machine_scale_set.html.markdown b/website/docs/r/linux_virtual_machine_scale_set.html.markdown index 17f59e446e0f..2565d85b87b9 100644 --- a/website/docs/r/linux_virtual_machine_scale_set.html.markdown +++ b/website/docs/r/linux_virtual_machine_scale_set.html.markdown @@ -156,7 +156,7 @@ The following arguments are supported: * `extensions_time_budget` - (Optional) Specifies the duration allocated for all extensions to start. The time duration should be between `15` minutes and `120` minutes (inclusive) and should be specified in ISO 8601 format. Defaults to `90` minutes (`PT1H30M`). -* `eviction_policy` - (Optional) The Policy which should be used Virtual Machines are Evicted from the Scale Set. Changing this forces a new resource to be created. +* `eviction_policy` - (Optional) Specifies the eviction policy for Virtual Machines in this Scale Set. Possible values are `Deallocate` and `Delete`. Changing this forces a new resource to be created. -> **NOTE:** This can only be configured when `priority` is set to `Spot`. diff --git a/website/docs/r/windows_virtual_machine.html.markdown b/website/docs/r/windows_virtual_machine.html.markdown index e905c8c4dcfd..87a33cd72667 100644 --- a/website/docs/r/windows_virtual_machine.html.markdown +++ b/website/docs/r/windows_virtual_machine.html.markdown @@ -133,7 +133,7 @@ The following arguments are supported: * `encryption_at_host_enabled` - (Optional) Should all of the disks (including the temp disk) attached to this Virtual Machine be encrypted by enabling Encryption at Host? -* `eviction_policy` - (Optional) Specifies what should happen when the Virtual Machine is evicted for price reasons when using a Spot instance. At this time the only supported value is `Deallocate`. Changing this forces a new resource to be created. +* `eviction_policy` - (Optional) Specifies what should happen when the Virtual Machine is evicted for price reasons when using a Spot instance. Possible values are `Deallocate` and `Delete`. Changing this forces a new resource to be created. -> **NOTE:** This can only be configured when `priority` is set to `Spot`. diff --git a/website/docs/r/windows_virtual_machine_scale_set.html.markdown b/website/docs/r/windows_virtual_machine_scale_set.html.markdown index f24200931197..c76e3d0fad61 100644 --- a/website/docs/r/windows_virtual_machine_scale_set.html.markdown +++ b/website/docs/r/windows_virtual_machine_scale_set.html.markdown @@ -140,7 +140,7 @@ The following arguments are supported: * `extensions_time_budget` - (Optional) Specifies the duration allocated for all extensions to start. The time duration should be between `15` minutes and `120` minutes (inclusive) and should be specified in ISO 8601 format. Defaults to `90` minutes (`PT1H30M`). -* `eviction_policy` - (Optional) The Policy which should be used Virtual Machines are Evicted from the Scale Set. Changing this forces a new resource to be created. +* `eviction_policy` - (Optional) Specifies the eviction policy for Virtual Machines in this Scale Set. Possible values are `Deallocate` and `Delete`. Changing this forces a new resource to be created. -> **NOTE:** This can only be configured when `priority` is set to `Spot`. From 50189597bbcc2397319795a7d8ad9d9460263d21 Mon Sep 17 00:00:00 2001 From: Allen Humphreys Date: Tue, 14 Jun 2022 10:44:05 -0400 Subject: [PATCH 3/3] Add acceptance tests for ephemeral OS disk on spot VMs with Delete eviction policy --- ...x_virtual_machine_resource_disk_os_test.go | 55 +++++++++++++++++++ ...s_virtual_machine_resource_disk_os_test.go | 52 ++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/internal/services/compute/linux_virtual_machine_resource_disk_os_test.go b/internal/services/compute/linux_virtual_machine_resource_disk_os_test.go index 185a41ceffef..ccfbc0940ef5 100644 --- a/internal/services/compute/linux_virtual_machine_resource_disk_os_test.go +++ b/internal/services/compute/linux_virtual_machine_resource_disk_os_test.go @@ -156,6 +156,21 @@ func TestAccLinuxVirtualMachine_diskOSEphemeralDefault(t *testing.T) { }) } +func TestAccLinuxVirtualMachine_diskOSDiskEphemeralSpot(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") + r := LinuxVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.diskOSEphemeralSpot(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("admin_password"), + }) +} + func TestAccLinuxVirtualMachine_diskOSEphemeralResourceDisk(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") r := LinuxVirtualMachineResource{} @@ -738,6 +753,46 @@ resource "azurerm_linux_virtual_machine" "test" { `, r.template(data), data.RandomInteger) } +func (r LinuxVirtualMachineResource) diskOSEphemeralSpot(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_F2s_v2" + admin_username = "adminuser" + priority = "Spot" + eviction_policy = "Delete" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + admin_ssh_key { + username = "adminuser" + public_key = local.first_public_key + } + + os_disk { + caching = "ReadOnly" + storage_account_type = "Standard_LRS" + + diff_disk_settings { + option = "Local" + } + } + + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } +} +`, r.template(data), data.RandomInteger) +} + func (r LinuxVirtualMachineResource) diskOSEphemeralResourceDisk(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/internal/services/compute/windows_virtual_machine_resource_disk_os_test.go b/internal/services/compute/windows_virtual_machine_resource_disk_os_test.go index 16261a27a83c..d2b2d1d46297 100644 --- a/internal/services/compute/windows_virtual_machine_resource_disk_os_test.go +++ b/internal/services/compute/windows_virtual_machine_resource_disk_os_test.go @@ -156,6 +156,21 @@ func TestAccWindowsVirtualMachine_diskOSEphemeralDefault(t *testing.T) { }) } +func TestAccWindowsVirtualMachine_diskOSEphemeralSpot(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") + r := WindowsVirtualMachineResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.diskOSEphemeralSpot(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("admin_password"), + }) +} + func TestAccWindowsVirtualMachine_diskOSEphemeralResourceDisk(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") r := WindowsVirtualMachineResource{} @@ -709,6 +724,43 @@ resource "azurerm_windows_virtual_machine" "test" { `, r.template(data)) } +func (r WindowsVirtualMachineResource) diskOSEphemeralSpot(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 + # Message="OS disk of Ephemeral VM with size greater than 32 GB is not allowed for VM size Standard_F2s_v2" + size = "Standard_DS3_v2" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + priority = "Spot" + eviction_policy = "Delete" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadOnly" + storage_account_type = "Standard_LRS" + + diff_disk_settings { + option = "Local" + } + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } +} +`, r.template(data)) +} + func (r WindowsVirtualMachineResource) diskOSEphemeralResourceDisk(data acceptance.TestData) string { return fmt.Sprintf(` %s