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

Fix reprovisioning of VM when we attach and detach data disk. #813

Merged
merged 4 commits into from
Feb 15, 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
2 changes: 0 additions & 2 deletions azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func resourceArmVirtualMachine() *schema.Resource {
"managed_disk_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
Expand All @@ -272,7 +271,6 @@ func resourceArmVirtualMachine() *schema.Resource {
"create_option": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

Expand Down
19 changes: 14 additions & 5 deletions azurerm/resource_arm_virtual_machine_managed_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func TestAccAzureRMVirtualMachine_bugAzureRM33(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachine_changeStorageDataDiskCreationOption(t *testing.T) {
func TestAccAzureRMVirtualMachine_attachSecondDataDiskWithAttachOption(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test currently fails:

------- Stdout: -------
=== RUN   TestAccAzureRMVirtualMachine_attachSecondDataDiskWithAttachOption
--- FAIL: TestAccAzureRMVirtualMachine_attachSecondDataDiskWithAttachOption (706.71s)
    testing.go:459: Step 1 error: Check failed: Check 3/3 error: azurerm_virtual_machine.test: Attribute 'storage_data_disk.0.create_option' expected "Attach", got "Empty"
FAIL

I've pushed a commit to fix this

var afterCreate, afterUpdate compute.VirtualMachine
resourceName := "azurerm_virtual_machine.test"
ri := acctest.RandInt()
Expand All @@ -251,7 +251,8 @@ func TestAccAzureRMVirtualMachine_changeStorageDataDiskCreationOption(t *testing
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &afterUpdate),
testAccCheckVirtualMachineRecreated(t, &afterCreate, &afterUpdate),
resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.create_option", "Attach"),
resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.create_option", "Empty"),
resource.TestCheckResourceAttr(resourceName, "storage_data_disk.1.create_option", "Attach"),
),
},
},
Expand Down Expand Up @@ -619,7 +620,7 @@ resource "azurerm_network_interface" "test" {
}

resource "azurerm_managed_disk" "test" {
name = "acctmd-%d"
name = "acctmd2-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_type = "Standard_LRS"
Expand Down Expand Up @@ -649,11 +650,19 @@ resource "azurerm_virtual_machine" "test" {
managed_disk_type = "Standard_LRS"
}

storage_data_disk {
name = "acctmd-%d"
create_option = "Empty"
disk_size_gb = "1"
lun = 0
managed_disk_type = "Standard_LRS"
}

storage_data_disk {
name = "${azurerm_managed_disk.test.name}"
create_option = "Attach"
disk_size_gb = "1"
lun = 0
lun = 1
managed_disk_id = "${azurerm_managed_disk.test.id}"
}

Expand All @@ -672,7 +681,7 @@ resource "azurerm_virtual_machine" "test" {
cost-center = "Ops"
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_empty(rInt int, location string) string {
Expand Down