# Azurerm\_virtual\_machine & Zones

**URL:** <https://discuss.hashicorp.com/t/azurerm-virtual-machine-zones/2310>\
**Category:** Terraform\
**Created:** [August 9, 2019, 3:06pm UTC](https://discuss.hashicorp.com/t/azurerm-virtual-machine-zones/2310 "2019-08-09T15:06:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe-Hodkinson](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/joe-hodkinson/32/1783_2.png) [@Joe-Hodkinson](https://discuss.hashicorp.com/u/Joe-Hodkinson)\
**Post date:** [August 9, 2019, 3:06pm UTC](https://discuss.hashicorp.com/t/azurerm-virtual-machine-zones/2310/1 "2019-08-09T15:06:25Z")

</div>

I’m hoping someone will be able to point me in the right direction of how to place a VM into an Azure zone. This is easy when it’s just one VM you’re deploying but I’m doing a count to deploy 5 VMs and would like to spread them out over 3 Azure zones. For example, 2 in Zone 1, 2 in zone 2 and 1 in zone 3.

The Zone parameter is a ‘list of a single item’ there a way to on each iteration of the loop (using count =5) to set the zone?

Example code:

resource “azurerm\_virtual\_machine” “vm\_app\_servers” {  
count = “${var.Number\_of\_App\_Machines}”  
zones = [" "] # This needs to be the zone number.

If I did something like this: zones = [“1”, “2”]

I get the error - Error: zones: attribute supports 1 item maximum, config has 2 declared. So I need a way to specify the zone.

Hope that makes sense?

Thanks, Joe

---

<div class="post-metadata">

**Author:** ![nickmhankins](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/nickmhankins/32/1194_2.png) [@nickmhankins](https://discuss.hashicorp.com/u/nickmhankins)\
**Post date:** [August 9, 2019, 4:31pm UTC](https://discuss.hashicorp.com/t/azurerm-virtual-machine-zones/2310/2 "2019-08-09T16:31:37Z")

</div>

Here is what we do for that same scenario:

```auto
resource "azurerm_virtual_machine" "vm" {
  count = var.vm_count
  name = "${var.vm_name}${count.index + 1}"
  location = var.resource_group_details["location"]
  resource_group_name = var.resource_group_details["name"]
  network_interface_ids = [azurerm_network_interface.nic[count.index].id]
  zones = [element(split(",", var.av_zone), count.index)]
  vm_size = var.vm_sku
  delete_os_disk_on_termination = "true"
  delete_data_disks_on_termination = "true"
}

```

Using `element()` will allow you to specify more VMs than there are zones and it will continue to loop through the list. For example you could pass in `zones = [1,2,3]` and `vmcount = 5` and it will place them in zones 1, 2, 3, 1, 2, respectively
