Create and Attach multiple disks using terraform

Perumal, Janakiraman 241 Reputation points
2020-12-09T03:40:06.7+00:00

Hi Folks,

I need to create multiple disks and attach them using terraform while creating VMs. Number of disks could be different and storage type like standard HDD/ Premium may also vary, sizes could be different.

I used locals variable within the code to achieve this, but i am afraid, i might need to update the locals for each project.

Is there a better way to handle this from custom var file?

regards,
Janakiraman

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,086 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
571 questions
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 33,141 Reputation points Microsoft Employee
    2020-12-09T17:41:37.76+00:00

    @Perumal, Janakiraman
    Since you question is related to Terraform you might get more responses by posting it to somewhere else, like Stack Overflow. There are two ways to handle data disks in terraform, they can be created with the VM using azurerm_virtual_machine with storage_data_disk or created and attached using azurerm_virtual_machine_data_disk_attachment. Some examples can be found here. For how to best handle the variables in Terraform I would refer you to the input variables page.

    Hope this helps. Let me know if you have further question or issues and I will be happy to assist.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments