From 2226bcaf9ef936f520f59d4dc4929ea46380cb36 Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Sat, 30 Sep 2017 13:46:22 +0200 Subject: [PATCH 1/3] Added test case TestAccAzureRMVirtualMachine_windowsMachineResize --- ...rm_virtual_machine_unmanaged_disks_test.go | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go b/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go index 014350e7e6cb..ddf231c250a6 100644 --- a/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go @@ -180,7 +180,7 @@ func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() - config := testAccAzureRMVirtualMachine_windowsUnattendedConfig(ri, testLocation()) + config := testAccAzureRMVirtualMachine_windowsUnattendedConfig(ri, testLocation(), "Standard_D1_v2") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -196,6 +196,32 @@ func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) { }) } +func TestAccAzureRMVirtualMachine_windowsMachineResize(t *testing.T) { + var vm compute.VirtualMachine + ri := acctest.RandInt() + preConfig := testAccAzureRMVirtualMachine_windowsUnattendedConfig(ri, testLocation(), "Standard_D1_v2") + postConfig := testAccAzureRMVirtualMachine_windowsUnattendedConfig(ri, testLocation(), "Standard_D2_v2") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + ), + }, + }, + }) +} + func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) { var vm compute.VirtualMachine ri := acctest.RandInt() @@ -1382,7 +1408,7 @@ resource "azurerm_virtual_machine" "test" { `, rInt, location, rInt, rInt, rInt, rInt, rInt) } -func testAccAzureRMVirtualMachine_windowsUnattendedConfig(rInt int, location string) string { +func testAccAzureRMVirtualMachine_windowsUnattendedConfig(rInt int, location string, vmSize string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1438,7 +1464,7 @@ resource "azurerm_virtual_machine" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_D1_v2" + vm_size = "%s" storage_image_reference { publisher = "MicrosoftWindowsServer" @@ -1471,7 +1497,7 @@ resource "azurerm_virtual_machine" "test" { } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, rInt, location, rInt, rInt, rInt, rInt, rInt, vmSize) } func testAccAzureRMVirtualMachine_diagnosticsProfile(rInt int, location string) string { From 1b6051890b18866d5d6ebf2de5adbce32299ec45 Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Sat, 30 Sep 2017 13:46:46 +0200 Subject: [PATCH 2/3] Added test case TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize --- ...urce_arm_virtual_machine_scale_set_test.go | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine_scale_set_test.go b/azurerm/resource_arm_virtual_machine_scale_set_test.go index 84a12f211a08..944bb7105be9 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set_test.go +++ b/azurerm/resource_arm_virtual_machine_scale_set_test.go @@ -121,7 +121,7 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(t *testing.T) { func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(t *testing.T) { ri := acctest.RandInt() - config := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, testLocation()) + config := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, testLocation(), "Standard_D1_v2") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -137,6 +137,31 @@ func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(t *testing.T) }) } +func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize(t *testing.T) { + ri := acctest.RandInt() + preConfig := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, testLocation(), "Standard_D1_v2") + postConfig := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, testLocation(), "Standard_D2_v2") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"), + ), + }, + }, + }) +} + func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(t *testing.T) { ri := acctest.RandInt() config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(ri, testLocation()) @@ -1080,7 +1105,7 @@ resource "azurerm_virtual_machine_scale_set" "test" { `, rInt, location, rInt, rInt, rInt, rInt, rInt) } -func testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(rInt int, location string, vmSize string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1108,7 +1133,7 @@ resource "azurerm_virtual_machine_scale_set" "test" { upgrade_policy_mode = "Manual" sku { - name = "Standard_D1_v2" + name = "%s" tier = "Standard" capacity = 2 } @@ -1161,7 +1186,7 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, rInt, location, rInt, rInt, rInt, vmSize, rInt) } func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(rInt int, location string) string { From 48f344d5e2461ad4d5aeff9627fc8ada8c6adcdb Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Sat, 30 Sep 2017 13:50:26 +0200 Subject: [PATCH 3/3] Fix crash when Terraform state contains an empty string for `additional_unattend_config.content` in resources `azurerm_virtual_machine` and `azurerm_virtual_machine_scale_set` --- azurerm/resource_arm_virtual_machine.go | 5 ++++- azurerm/resource_arm_virtual_machine_scale_set.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 26bbd000f701..6f630b12d1ea 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -1307,7 +1307,10 @@ func expandAzureRmVirtualMachineOsProfileWindowsConfig(d *schema.ResourceData) ( PassName: compute.PassNames(pass), ComponentName: compute.ComponentNames(component), SettingName: compute.SettingNames(settingName), - Content: &content, + } + + if content != "" { + addContent.Content = &content } additionalConfigContent = append(additionalConfigContent, addContent) diff --git a/azurerm/resource_arm_virtual_machine_scale_set.go b/azurerm/resource_arm_virtual_machine_scale_set.go index bcdf614d3e44..d6c42af9bd29 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/azurerm/resource_arm_virtual_machine_scale_set.go @@ -1455,7 +1455,10 @@ func expandAzureRmVirtualMachineScaleSetOsProfileWindowsConfig(d *schema.Resourc PassName: compute.PassNames(pass), ComponentName: compute.ComponentNames(component), SettingName: compute.SettingNames(settingName), - Content: &content, + } + + if content != "" { + addContent.Content = &content } additionalConfigContent = append(additionalConfigContent, addContent)