Skip to content

Commit

Permalink
Bug Fix of azurerm_virtual_machine.storage_os_disk.image_uri (#1799)
Browse files Browse the repository at this point in the history
* Add repro test for bug #838

* Set image_uri back to schema

* Add image_uri check in test case
  • Loading branch information
Junyi Yi authored and tombuildsstuff committed Aug 23, 2018
1 parent 8b25b8c commit bbc09ca
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,9 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk, diskInfo *compute.
if disk.Vhd != nil {
result["vhd_uri"] = *disk.Vhd.URI
}
if disk.Image != nil && disk.Image.URI != nil {
result["image_uri"] = *disk.Image.URI
}
if disk.ManagedDisk != nil {
result["managed_disk_type"] = string(disk.ManagedDisk.StorageAccountType)
if disk.ManagedDisk.ID != nil {
Expand Down
68 changes: 68 additions & 0 deletions azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package azurerm

import (
"fmt"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -102,6 +103,29 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(t *testing.T) {
var vm, mirrorVm compute.VirtualMachine
ri := acctest.RandInt()
config := testAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(ri, testLocation())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.mirror", &mirrorVm),
testCheckAzureRMVirtualMachineVHDExistence("myosdisk1.vhd", true),
testCheckAzureRMVirtualMachineVHDExistence("mirrorosdisk.vhd", true),
resource.TestMatchResourceAttr("azurerm_virtual_machine.mirror", "storage_os_disk.0.image_uri", regexp.MustCompile("myosdisk1.vhd$")),
),
},
},
})
}

func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) {
var vm compute.VirtualMachine

Expand Down Expand Up @@ -919,6 +943,50 @@ resource "azurerm_virtual_machine" "test" {
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(rInt int, location string) string {
baseConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(rInt, location)
return fmt.Sprintf(`%s
resource "azurerm_network_interface" "mirror" {
name = "acctmirrorni-%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" "mirror" {
name = "acctmirrorvm-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
network_interface_ids = ["${azurerm_network_interface.mirror.id}"]
vm_size = "Standard_F2"
delete_os_disk_on_termination = false
os_profile {
computer_name = "hnmirror%d"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
storage_os_disk {
name = "mirror"
image_uri = "${azurerm_virtual_machine.test.storage_os_disk.0.vhd_uri}"
vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/mirrorosdisk.vhd"
create_option = "FromImage"
os_type = "Linux"
}
}
`, baseConfig, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachine_machineNameBeforeUpdate(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit bbc09ca

Please sign in to comment.