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

AzureRM Managed Disks #12455

Merged
merged 43 commits into from
Apr 6, 2017
Merged

AzureRM Managed Disks #12455

merged 43 commits into from
Apr 6, 2017

Conversation

brandontosch
Copy link
Contributor

@brandontosch brandontosch commented Mar 6, 2017

Implemented support for Managed Disks (#11874) as standalone resources and as part of a virtual machine. My team is in the middle of a migration to Azure and needed this feature so decided I would try and help out with getting it implemented. Hope this helps!

Acceptance test results

@edevil
Copy link
Contributor

edevil commented Mar 21, 2017

Any news on this?

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
//"regexp"
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: can we remove this commented include?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed, thanks!

@@ -190,7 +208,24 @@ func resourceArmVirtualMachine() *schema.Resource {

"vhd_uri": {
Type: schema.TypeString,
Required: true,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @brandontosch

Thanks for pushing those updates - sorry for the delay in getting back to you here.

The issue was that it tries to lookup the conflicts from the root of the schema using the keys provided inside ConflictsWith. So trying to locate storage_data_disk.vhd_uri would never succeed since it doesn't contain the index and storage_data_disk is a list. This would cause validation to always succeed and lead to an error when trying to create the resource.

Ah, apologies - I wasn't aware ConflictsWith didn't support this.

IMHO it makes sense to expect storage_data_disk.vhd_uri to work for ConflictsWith so I added some code during the validation to check the key that is being validated for the index (since it is there) and then add it to the conflicting key being searched for so that it can check for a value appropriately. Added some tests in there too for various scenarios to make sure it doesn't garble anything up for other cases.

I'd agree that the behaviour is expected, so thanks for adding support for this! Given that's a change to the Core it'd need further discussion, so that we're not blocking this PR on that (as it otherwise looks good to merge!) - can we pull the ConflictsWith changes out into a separate PR?

Thanks!

@servercharlie
Copy link

+1 love this @brandontosch !

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

Hey @brandontosch

Thanks for the continued effort on this - it's really close now!

I've run the tests and all but one of the tests are passing - TestAccAzureRMManagedDisk_import is failing as the disk_size_gb field isn't set. I've tried updating this to 45 (to match the disk size) and then the tests pass as expected - is it possible to update this?

Thanks!

resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_type = "Standard_LRS"
create_option = "Import"
source_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd"
Copy link
Contributor

Choose a reason for hiding this comment

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

The TestAccAzureRMManagedDisk_import test is currently failing since disk_size_gb isn't specified. Setting this value to 45 lets the test pass, thus is it possible to update this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doh! I'll update and do a full re-run as well just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok @tombuildsstuff, all green on my side. Thanks!

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

LGTM :)

@tombuildsstuff
Copy link
Contributor

👋 Hi @brandontosch

Thanks for pushing the latest changes - I've taken another look through and it looks good to me :)

I've run the tests and (ignoring an unrelated test failure) everything looks great:

=== RUN   TestAccAzureRMManagedDisk_importEmpty
--- PASS: TestAccAzureRMManagedDisk_importEmpty (304.93s)
=== RUN   TestAccAzureRMVirtualMachine_importBasic
--- PASS: TestAccAzureRMVirtualMachine_importBasic (557.04s)
=== RUN   TestAccAzureRMVirtualMachine_importBasic_managedDisk
--- PASS: TestAccAzureRMVirtualMachine_importBasic_managedDisk (600.83s)
=== RUN   TestAccAzureRMManagedDisk_empty
--- PASS: TestAccAzureRMManagedDisk_empty (463.42s)
=== RUN   TestAccAzureRMManagedDisk_import
--- PASS: TestAccAzureRMManagedDisk_import (647.21s)
=== RUN   TestAccAzureRMManagedDisk_copy
--- PASS: TestAccAzureRMManagedDisk_copy (555.58s)
=== RUN   TestAccAzureRMManagedDisk_update
--- PASS: TestAccAzureRMManagedDisk_update (436.33s)
=== RUN   TestAccAzureRMVirtualMachine_basicLinuxMachine
--- PASS: TestAccAzureRMVirtualMachine_basicLinuxMachine (538.00s)
=== RUN   TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit
--- PASS: TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit (582.79s)
=== RUN   TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit
--- PASS: TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit (475.44s)
=== RUN   TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach
--- PASS: TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach (619.69s)
=== RUN   TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears
--- PASS: TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears (430.60s)
=== RUN   TestAccAzureRMVirtualMachine_withDataDisk
--- PASS: TestAccAzureRMVirtualMachine_withDataDisk (596.94s)
=== RUN   TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit
--- PASS: TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit (456.40s)
=== RUN   TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit
--- PASS: TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit (603.36s)
=== RUN   TestAccAzureRMVirtualMachine_tags
--- PASS: TestAccAzureRMVirtualMachine_tags (1255.74s)
=== RUN   TestAccAzureRMVirtualMachine_updateMachineSize
--- PASS: TestAccAzureRMVirtualMachine_updateMachineSize (618.44s)
=== RUN   TestAccAzureRMVirtualMachine_basicWindowsMachine
--- PASS: TestAccAzureRMVirtualMachine_basicWindowsMachine (673.26s)
=== RUN   TestAccAzureRMVirtualMachine_windowsUnattendedConfig
--- PASS: TestAccAzureRMVirtualMachine_windowsUnattendedConfig (557.58s)
=== RUN   TestAccAzureRMVirtualMachine_diagnosticsProfile
--- PASS: TestAccAzureRMVirtualMachine_diagnosticsProfile (675.49s)
=== RUN   TestAccAzureRMVirtualMachine_winRMConfig
--- PASS: TestAccAzureRMVirtualMachine_winRMConfig (673.85s)
=== RUN   TestAccAzureRMVirtualMachine_deleteVHDOptOut
--- PASS: TestAccAzureRMVirtualMachine_deleteVHDOptOut (554.61s)
=== RUN   TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut
--- PASS: TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut (470.62s)
=== RUN   TestAccAzureRMVirtualMachine_deleteVHDOptIn
--- PASS: TestAccAzureRMVirtualMachine_deleteVHDOptIn (573.76s)
=== RUN   TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn
--- PASS: TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn (668.17s)
=== RUN   TestAccAzureRMVirtualMachine_ChangeComputerName
--- PASS: TestAccAzureRMVirtualMachine_ChangeComputerName (976.94s)
=== RUN   TestAccAzureRMVirtualMachine_ChangeAvailabilitySet
--- PASS: TestAccAzureRMVirtualMachine_ChangeAvailabilitySet (931.75s)
=== RUN   TestAccAzureRMVirtualMachine_changeStorageImageReference
--- PASS: TestAccAzureRMVirtualMachine_changeStorageImageReference (1211.15s)
=== RUN   TestAccAzureRMVirtualMachine_changeOSDiskVhdUri
--- PASS: TestAccAzureRMVirtualMachine_changeOSDiskVhdUri (923.36s)
=== RUN   TestAccAzureRMVirtualMachine_plan
--- PASS: TestAccAzureRMVirtualMachine_plan (587.10s)
=== RUN   TestAccAzureRMVirtualMachine_changeSSHKey
--- PASS: TestAccAzureRMVirtualMachine_changeSSHKey (685.61s)
=== RUN   TestAccAzureRMVirtualMachine_osDiskTypeConflict
--- PASS: TestAccAzureRMVirtualMachine_osDiskTypeConflict (148.55s)
=== RUN   TestAccAzureRMVirtualMachine_dataDiskTypeConflict
--- PASS: TestAccAzureRMVirtualMachine_dataDiskTypeConflict (148.17s)
=== RUN   TestAccAzureRMVirtualMachine_windowsLicenseType
--- FAIL: TestAccAzureRMVirtualMachine_windowsLicenseType (176.17s)
	testing.go:273: Step 0 error: Error applying: 1 error(s) occurred:

		* azurerm_virtual_machine.test: 1 error(s) occurred:

		* azurerm_virtual_machine.test: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ImageNotFound" Message="The platform image 'MicrosoftWindowsServer:WindowsServer-HUB:2008-R2-SP1-HUB:latest' is not available. Verify that all fields in the storage profile are correct."
=== RUN   TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId
--- PASS: TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId (566.55s)

Thanks again for all your effort here :)

@tombuildsstuff tombuildsstuff merged commit 6f2551e into hashicorp:master Apr 6, 2017
tombuildsstuff added a commit that referenced this pull request Apr 6, 2017
@brandontosch
Copy link
Contributor Author

Awesome, thanks for your help getting this merged in @tombuildsstuff!
Glad I could be of assistance. I'll try and keep an eye out, but if there is anything else I could help with on the azure side please don't hesitate to ask. We're investing heavily in a move to azure and using terraform right now so I'd be happy to flush out any other features/fixes if needed.

@bpoland
Copy link

bpoland commented Apr 12, 2017

@brandontosch thanks for this great work on managed disks! One other gap that I have noticed working with Terraform in Azure is lack of App Gateway support, and the inability to link a virtual machine scale set or network interface to the app gateway (currently you can only link the VMSS/NI to a load balancer).

#8670

There is already a merge request but it seems to have stalled (last commit was end of November) and it doesn't include the tweaks to the VMSS or NI. If you have time to finish that up, I know I would greatly appreciate it and I'm sure many others would as well.

#10413

@brandontosch
Copy link
Contributor Author

@bpoland thanks for the suggestion! I think we were actually going to need app gateway support as well so I'll try and hop over there and take a look when I can.

@dobrerazvan
Copy link

@brandontosch

I tried to use your managed disk work with custom images (use a vhd instead of an azure provided image) and i get:

* azurerm_virtual_machine.test: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidParameter" Message="Parameter 'osDisk.image' is not allowed."

The code is in: https://gist.github.com/dobrerazvan/b4a6bfbf1c6648b20ae0aad39dd6ac74

Thanks

@brandontosch
Copy link
Contributor Author

brandontosch commented Apr 19, 2017

@dobrerazvan it looks like this won't be able to be accomplished without a code change.
Can you open an issue for this? I'll try and find the proper solution when I get some time.

Actually, I don't think there is a path available to make this work on the azure api side of things.. Looks like building a VM's OS disk from a custom VHD is not supported for managed disks right now. Hopefully if they add that support then the config you specified should work because it looks like it should in my opinion.

@dobrerazvan
Copy link

@brandontosch

Thanks for the reply.

I tried the solution you suggested with standalone managed disk and use the Import option for create options. Seems to create the volume with the custom os on top. I wasn't able to find a way through azure portal to spin up a vm from that managed disk with the os. The error i get is:

* azurerm_virtual_machine.test: 1 error(s) occurred:

* azurerm_virtual_machine.test: compute.VirtualMachinesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="InvalidParameter" Message="Parameter 'osProfile' is not allowed."

gist: https://gist.github.com/dobrerazvan/df4fb12a22303f885856c0be6b571007

@brandontosch
Copy link
Contributor Author

@dobrerazvan looks like an issue has been opened to track this #13932 and I think I might have a fix for it. I'll open up a PR with what I think can work and it would be much appreciated if you could try testing it out to see if it works for your scenario as well.

@ghost
Copy link

ghost commented Apr 13, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants