Terraform-provider-azurerm: no way to conditionally attached storage disks

Created on 16 Mar 2018  ·  3Comments  ·  Source: terraform-providers/terraform-provider-azurerm

Terraform Version

Terraform v0.11.3

  • provider.azurerm v1.2.0

Affected Resource(s)

virtual_machine

The storage_data_disk will go ahead and try to add a disk to the vm even with empty name and 0 size.
this means there is no way to conditionally enable/disable adding a data disk to a vm.

question servicvirtual-machine

Most helpful comment

not looking to create a completely generic module, but some of our vms require attaching data disks and some do not.
due to the number of configuration blocks required, instead of duplicating the vm config (which means duplicating a lot of other related config inside it), easier to just conditionally allow adding a data disk.

i do think the feature request you pointed to could be useful in this case

All 3 comments

hey @pdeva

Thanks for opening this issue :)

The storage_data_disk will go ahead and try to add a disk to the vm even with empty name and 0 size.

Terraform will try and create resources and disks for anything present in the configuration; in this instance we're passing the values through to Azure which is what's returning any errors here (or at least, I believe that's what's happening here 😄).

Out of interest are you looking to create a generic module for a VM?

There's a separate feature request open to add a separate resource to allow attaching disks outside of the VM resource which may solve this problem, but that needs some research to see if it's feasible given how disks are attached in Azure. Given this appears to be a duplicate of that feature request - I'm going to close this issue in favour of that one for the moment.

Thanks!

not looking to create a completely generic module, but some of our vms require attaching data disks and some do not.
due to the number of configuration blocks required, instead of duplicating the vm config (which means duplicating a lot of other related config inside it), easier to just conditionally allow adding a data disk.

i do think the feature request you pointed to could be useful in this case

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 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings