diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/resource_arm_virtual_machine.go index 0e2794726ddc..4cabbf3e99b2 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/resource_arm_virtual_machine.go @@ -368,10 +368,12 @@ func resourceArmVirtualMachine() *schema.Resource { "provision_vm_agent": { Type: schema.TypeBool, Optional: true, + Default: false, }, "enable_automatic_upgrades": { Type: schema.TypeBool, Optional: true, + Default: false, }, "winrm": { Type: schema.TypeList, @@ -892,13 +894,17 @@ func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int func resourceArmVirtualMachineStorageOsProfileWindowsConfigHash(v interface{}) int { var buf bytes.Buffer - m := v.(map[string]interface{}) - if m["provision_vm_agent"] != nil { - buf.WriteString(fmt.Sprintf("%t-", m["provision_vm_agent"].(bool))) - } - if m["enable_automatic_upgrades"] != nil { - buf.WriteString(fmt.Sprintf("%t-", m["enable_automatic_upgrades"].(bool))) + + if v != nil { + m := v.(map[string]interface{}) + if m["provision_vm_agent"] != nil { + buf.WriteString(fmt.Sprintf("%t-", m["provision_vm_agent"].(bool))) + } + if m["enable_automatic_upgrades"] != nil { + buf.WriteString(fmt.Sprintf("%t-", m["enable_automatic_upgrades"].(bool))) + } } + return hashcode.String(buf.String()) } diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/resource_arm_virtual_machine_managed_disks_test.go index 48b0ad2c52ed..76942fc4696a 100644 --- a/azurerm/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/resource_arm_virtual_machine_managed_disks_test.go @@ -209,6 +209,22 @@ func TestAccAzureRMVirtualMachine_dataDiskTypeConflict(t *testing.T) { }) } +func TestAccAzureRMVirtualMachine_bugAzureRM33(t *testing.T) { + ri := acctest.RandInt() + rs := acctest.RandString(7) + config := testAccAzureRMVirtualMachine_bugAzureRM33(ri, rs, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineDestroy, + Steps: []resource.TestStep{ + { + Config: config, + }, + }, + }) +} + func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -931,6 +947,76 @@ resource "azurerm_virtual_machine" "test" { `, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) } +func testAccAzureRMVirtualMachine_bugAzureRM33(rInt int, rString string, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm%s" + 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_F1" + + storage_image_reference { + publisher = "MicrosoftWindowsServer" + offer = "WindowsServer" + sku = "2012-Datacenter" + version = "latest" + } + + storage_os_disk { + name = "myosdisk1" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "acctvm%s" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_windows_config {} + + tags { + environment = "Production" + cost-center = "Ops" + } +} +`, rInt, location, rInt, rInt, rInt, rString, rString) +} + func testCheckAzureRMVirtualMachineManagedDiskExists(managedDiskID *string, shouldExist bool) resource.TestCheckFunc { return func(s *terraform.State) error { d, err := testGetAzureRMVirtualMachineManagedDisk(managedDiskID)