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

Bug Fix of azurerm_virtual_machine.storage_os_disk.image_uri #1799

Merged
merged 3 commits into from
Aug 23, 2018
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
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),
Copy link
Contributor

@tombuildsstuff tombuildsstuff Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also check the image_uri field is set correctly in the state here by using:

resource.TestCheckResourceAttrSet("azurerm_virtual_machine.mirror", "storage_os_disk.0.image_uri")
``` #Resolved

Copy link
Collaborator

@WodansSon WodansSon Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this same thing to him last night and I believe he has a commit with the image_uri check in it ready to push. #Resolved

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