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_virtual_machine not able to remove/reattach disks that were originally created during initial provisioning #89

Closed
hashibot opened this issue Jun 13, 2017 · 3 comments

Comments

@hashibot
Copy link

This issue was originally opened by @matthewbrahms as hashicorp/terraform#14636. It was migrated here as part of the provider split. The original body of the issue is below.


Terraform Version

terraform version 0.9.5

Affected Resource(s)

  • azurerm_virtual_machine
  • azurerm_availability_set

May be a core problem?

Debug Output

https://gist.github.com/matthewbrahms/37f0b93134c2fb3631902ab63563c960

Expected Behavior

Should have created new VM's in the availability set and attached the existing disks to the new servers.

Actual Behavior

Fails creation of resources because disks already exist.

Steps to Reproduce

  • create availability set
  • created two independent VM's that we forgot to attach to the availability set on the initial creation
  • went back and added the "availability_set_id" parameter to each vm
  • terraform plan showed that it would create new resources
  • terraform apply deleted the old vm's, but could not create new ones due to the output in the above gist

Important Factoids

Using AzureRM and new portal if it helps at all to view what happened from the Azure side. VM's now exist but they say "Failed" on them.

@tombuildsstuff
Copy link
Contributor

Hey @matthewbrahms

Thanks for opening this issue - apologies for the delayed response here!

The error message you're seeing is because the disks already exist when trying to create the VM's with a create_option of Empty or FromImage:

compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=200 -- Original Error: Long running operation terminated with status 'Failed': Code="TargetDiskBlobAlreadyExists" Message="Blob https://csstoragehackathon.blob.core.windows.net/cs-storagecontainer-hackathon/rancher-master-1.vhd already exists. Please provide a different blob URI as target for disk 'rancher-master-1'."

There's two ways to work around this issue - the first would be to update the Terraform Configuration to use a create_option of Attach - which will attach the existing disks. Alternatively - if the data on the disks isn't needed - it's possible to set the two parameters delete_os_disk_on_termination and delete_data_disks_on_termination on the azurerm_virtual_machine resource as appropriate which will delete and re-create the disks when the VM needs to be recreated.

Would you be able to take a look and see if that solves your issue? In the interim I'm going to close this issue - but please feel free to re-open it if there's still an issue here and we'll take another look :)

Thanks!

@matthewbrahms
Copy link

@tombuildsstuff The deletion on termination option works! Thanks for the explanation...makes complete sense. Cheers!

@ghost
Copy link

ghost commented Apr 1, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

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

No branches or pull requests

4 participants