From 02b64ea45fee22dd7bf1eb402ef2c219b3b1efa5 Mon Sep 17 00:00:00 2001 From: NilsBusche Date: Thu, 20 Aug 2020 08:55:59 +0200 Subject: [PATCH 1/2] Make update of allow_extensions_operations independent from provision_vm_agent. There is no API restriction which does not allow enabling allow_extensions_operations if provision_vm_agent is false. For example you can install the agent manually and after that enable allow_extensions_operations. --- .../services/compute/linux_virtual_machine_resource.go | 5 ----- .../services/compute/windows_virtual_machine_resource.go | 5 ----- 2 files changed, 10 deletions(-) diff --git a/azurerm/internal/services/compute/linux_virtual_machine_resource.go b/azurerm/internal/services/compute/linux_virtual_machine_resource.go index ca8efdf94a26..f215c7bed7c7 100644 --- a/azurerm/internal/services/compute/linux_virtual_machine_resource.go +++ b/azurerm/internal/services/compute/linux_virtual_machine_resource.go @@ -816,13 +816,8 @@ func resourceLinuxVirtualMachineUpdate(d *schema.ResourceData, meta interface{}) } if d.HasChange("allow_extension_operations") { - provisionVMAgent := d.Get("provision_vm_agent").(bool) allowExtensionOperations := d.Get("allow_extension_operations").(bool) - if !provisionVMAgent && allowExtensionOperations { - return fmt.Errorf("`allow_extension_operations` cannot be set to `true` when `provision_vm_agent` is set to `false`") - } - shouldUpdate = true if update.OsProfile == nil { diff --git a/azurerm/internal/services/compute/windows_virtual_machine_resource.go b/azurerm/internal/services/compute/windows_virtual_machine_resource.go index 743291b7408b..819fe21ebc14 100644 --- a/azurerm/internal/services/compute/windows_virtual_machine_resource.go +++ b/azurerm/internal/services/compute/windows_virtual_machine_resource.go @@ -740,13 +740,8 @@ func resourceWindowsVirtualMachineUpdate(d *schema.ResourceData, meta interface{ } if d.HasChange("allow_extension_operations") { - provisionVMAgent := d.Get("provision_vm_agent").(bool) allowExtensionOperations := d.Get("allow_extension_operations").(bool) - if !provisionVMAgent && allowExtensionOperations { - return fmt.Errorf("`allow_extension_operations` cannot be set to `true` when `provision_vm_agent` is set to `false`") - } - shouldUpdate = true if update.OsProfile == nil { From f7abb29667118134c30f1766c80163281999e873 Mon Sep 17 00:00:00 2001 From: NilsBusche Date: Fri, 28 Aug 2020 09:42:16 +0200 Subject: [PATCH 2/2] Add tests for updating allow_extensions_operations if provision_vm_agent is false. --- ...nux_virtual_machine_resource_other_test.go | 102 ++++++++++++++++++ ...ows_virtual_machine_resource_other_test.go | 98 +++++++++++++++++ 2 files changed, 200 insertions(+) diff --git a/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go b/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go index b2bb91be85d4..dad8105df126 100644 --- a/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go +++ b/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go @@ -77,6 +77,34 @@ func TestAccLinuxVirtualMachine_otherAllowExtensionOperationsUpdated(t *testing. }) } +func TestAccLinuxVirtualMachine_otherAllowExtensionOperationsUpdatedWithoutVmAgent(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: checkLinuxVirtualMachineIsDestroyed, + Steps: []resource.TestStep{ + { + Config: testLinuxVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data), + Check: resource.ComposeTestCheckFunc( + checkLinuxVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "false"), + ), + }, + data.ImportStep(), + { + Config: testLinuxVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data), + Check: resource.ComposeTestCheckFunc( + checkLinuxVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccLinuxVirtualMachine_otherBootDiagnostics(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test") @@ -425,6 +453,80 @@ resource "azurerm_linux_virtual_machine" "test" { `, template, data.RandomInteger) } +func testLinuxVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data acceptance.TestData) string { + template := testLinuxVirtualMachine_template(data) + 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_F2" + admin_username = "adminuser" + allow_extension_operations = false + provision_vm_agent = false + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + 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 = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } +} +`, template, data.RandomInteger) +} + +func testLinuxVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data acceptance.TestData) string { + template := testLinuxVirtualMachine_template(data) + 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_F2" + admin_username = "adminuser" + allow_extension_operations = true + provision_vm_agent = false + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + 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 = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } +} +`, template, data.RandomInteger) +} + func testLinuxVirtualMachine_otherBootDiagnostics(data acceptance.TestData) string { template := testLinuxVirtualMachine_otherBootDiagnosticsTemplate(data) return fmt.Sprintf(` diff --git a/azurerm/internal/services/compute/tests/windows_virtual_machine_resource_other_test.go b/azurerm/internal/services/compute/tests/windows_virtual_machine_resource_other_test.go index 9aff629513a2..f07025dc30a9 100644 --- a/azurerm/internal/services/compute/tests/windows_virtual_machine_resource_other_test.go +++ b/azurerm/internal/services/compute/tests/windows_virtual_machine_resource_other_test.go @@ -107,6 +107,38 @@ func TestAccWindowsVirtualMachine_otherAllowExtensionOperationsUpdated(t *testin }) } +func TestAccWindowsVirtualMachine_otherAllowExtensionOperationsUpdatedWithoutVmAgent(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: checkWindowsVirtualMachineIsDestroyed, + Steps: []resource.TestStep{ + { + Config: testWindowsVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data), + Check: resource.ComposeTestCheckFunc( + checkWindowsVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "false"), + ), + }, + data.ImportStep( + "admin_password", + ), + { + Config: testWindowsVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data), + Check: resource.ComposeTestCheckFunc( + checkWindowsVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "allow_extension_operations", "true"), + ), + }, + data.ImportStep( + "admin_password", + ), + }, + }) +} + func TestAccWindowsVirtualMachine_otherBootDiagnostics(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine", "test") @@ -683,6 +715,72 @@ resource "azurerm_windows_virtual_machine" "test" { `, template) } +func testWindowsVirtualMachine_otherAllowExtensionOperationsDisabledWithoutVmAgent(data acceptance.TestData) string { + template := testWindowsVirtualMachine_template(data) + 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_F2" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + allow_extension_operations = false + provision_vm_agent = false + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } +} +`, template) +} + +func testWindowsVirtualMachine_otherAllowExtensionOperationsEnabledWithoutVmAgent(data acceptance.TestData) string { + template := testWindowsVirtualMachine_template(data) + 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_F2" + admin_username = "adminuser" + admin_password = "P@$$w0rd1234!" + allow_extension_operations = true + provision_vm_agent = false + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + + source_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2016-Datacenter" + version = "latest" + } +} +`, template) +} + func testWindowsVirtualMachine_otherBootDiagnostics(data acceptance.TestData) string { template := testWindowsVirtualMachine_otherBootDiagnosticsTemplate(data) return fmt.Sprintf(`