0
votes

Need more detail on how to create a resource for placing an IaaS into an specific availability zone during azurerm terraform deployment?

https://www.terraform.io/docs/providers/azurerm/r/virtual_machine.html#zones

This link does not give me enough detail on how to write the option of choosing a specific availability zone for a VM that will be deployed using azure terraform.

zones  - (Optional) A list of a single item of the Availability Zone which the Virtual Machine should be allocated in.

1

1 Answers

0
votes

The documentation is saying that you need a terraform list with a single item which is the zone that you want the VM created. Here is what that looks like for East US using Zone 1.

resource "azurerm_virtual_machine" "main" {
  name                  = "${var.prefix}-vm"
  location              = "${azurerm_resource_group.main.location}"
  resource_group_name   = "${azurerm_resource_group.main.name}"
  network_interface_ids = ["${azurerm_network_interface.main.id}"]
  vm_size               = "Standard_DS1_v2"

  # Zone info
  zones = [1]

  storage_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }
  storage_os_disk {
    name              = "myosdisk1"
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }
  os_profile {
    computer_name  = "hostname"
    admin_username = "testadmin"
    admin_password = "Password1234!"
  }
  os_profile_linux_config {
    disable_password_authentication = false
  }
  tags = {
    environment = "staging"
  }
}