Skip to content

Commit

Permalink
Allow Delete eviction policy on Azure VMs (hashicorp#17226)
Browse files Browse the repository at this point in the history
  • Loading branch information
allenhumphreys authored Aug 16, 2022
1 parent c3dd75f commit 5e8d5ea
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,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),
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,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),
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/linux_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,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`.

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/windows_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,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`.

Expand Down

0 comments on commit 5e8d5ea

Please sign in to comment.