Skip to content

Commit

Permalink
azurerm_linux_virtual_machine, azurerm_windows_virtual_machine - …
Browse files Browse the repository at this point in the history
…Support `hibernation_enabled` (#25807)
  • Loading branch information
ms-zhenhua authored May 6, 2024
1 parent c268a2f commit 60e8cf8
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,21 @@ func TestAccLinuxVirtualMachine_otherTerminationNotificationTimeout(t *testing.T
})
}

func TestAccLinuxVirtualMachine_otherHibernation(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.otherHibernation(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccLinuxVirtualMachine_otherUltraSsdDefault(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}
Expand Down Expand Up @@ -2637,6 +2652,46 @@ resource "azurerm_linux_virtual_machine" "test" {
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherHibernation(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_D16as_v5"
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"
disk_size_gb = 128
}
source_image_reference {
publisher = "Canonical"
offer = "0001-com-ubuntu-server-jammy"
sku = "22_04-lts"
version = "latest"
}
additional_capabilities {
hibernation_enabled = true
}
}
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherUltraSsd(data acceptance.TestData, ultraSsdEnabled bool) string {
return fmt.Sprintf(`
%s
Expand Down
17 changes: 16 additions & 1 deletion internal/services/compute/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ func virtualMachineAdditionalCapabilitiesSchema() *pluginsdk.Schema {
Optional: true,
Default: false,
},

"hibernation_enabled": {
Type: pluginsdk.TypeBool,
ForceNew: true,
Optional: true,
Default: false,
},
},
},
}
Expand All @@ -49,6 +56,8 @@ func expandVirtualMachineAdditionalCapabilities(input []interface{}) *virtualmac
raw := input[0].(map[string]interface{})

capabilities.UltraSSDEnabled = pointer.To(raw["ultra_ssd_enabled"].(bool))

capabilities.HibernationEnabled = pointer.To(raw["hibernation_enabled"].(bool))
}

return &capabilities
Expand All @@ -65,9 +74,15 @@ func flattenVirtualMachineAdditionalCapabilities(input *virtualmachines.Addition
ultraSsdEnabled = *input.UltraSSDEnabled
}

hibernationEnabled := false
if input.HibernationEnabled != nil {
hibernationEnabled = *input.HibernationEnabled
}

return []interface{}{
map[string]interface{}{
"ultra_ssd_enabled": ultraSsdEnabled,
"ultra_ssd_enabled": ultraSsdEnabled,
"hibernation_enabled": hibernationEnabled,
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,21 @@ func TestAccWindowsVirtualMachine_otherTimeZone(t *testing.T) {
})
}

func TestAccWindowsVirtualMachine_otherHibernation(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test")
r := WindowsVirtualMachineResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.otherHibernation(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
})
}

func TestAccWindowsVirtualMachine_otherUltraSsdDefault(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test")
r := WindowsVirtualMachineResource{}
Expand Down Expand Up @@ -3033,6 +3048,42 @@ resource "azurerm_windows_virtual_machine" "test" {
`, r.template(data))
}

func (r WindowsVirtualMachineResource) otherHibernation(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_D16as_v5"
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"
disk_size_gb = 128
}
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2019-Datacenter"
version = "latest"
}
additional_capabilities {
hibernation_enabled = true
}
}
`, r.template(data))
}

func (r WindowsVirtualMachineResource) otherUltraSsd(data acceptance.TestData, ultraSsdEnabled bool) string {
return fmt.Sprintf(`
%s
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/linux_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ A `additional_capabilities` block supports the following:

* `ultra_ssd_enabled` - (Optional) Should the capacity to enable Data Disks of the `UltraSSD_LRS` storage account type be supported on this Virtual Machine? Defaults to `false`.

* `hibernation_enabled` - (Optional) Whether to enable the hibernation capability or not. Changing this forces a new Linux Virtual Machine to be created.

---

A `admin_ssh_key` block supports the following:
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/windows_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ A `additional_capabilities` block supports the following:

* `ultra_ssd_enabled` - (Optional) Should the capacity to enable Data Disks of the `UltraSSD_LRS` storage account type be supported on this Virtual Machine? Defaults to `false`.

* `hibernation_enabled` - (Optional) Whether to enable the hibernation capability or not. Changing this forces a new Windows Virtual Machine to be created.

---

A `additional_unattend_content` block supports the following:
Expand Down

0 comments on commit 60e8cf8

Please sign in to comment.