Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_*_virtual_machine - additional_capabilities.0.ultra_ssd_enabled can now be added during update #24274

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,28 @@ func TestAccLinuxVirtualMachine_otherUltraSsdUpdated(t *testing.T) {
})
}

func TestAccLinuxVirtualMachine_otherUltraSsdEmptyToUpdate(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{}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
})
}

Expand Down Expand Up @@ -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
Expand Down
Loading