2016-12-15 63 views
0

我想用teraaform来完成这些工作。我将同时创建多个vms,例如10. 而且我将使用静态IP选项。
让我们说我的IP开始与将故障域绑定到azure和Terraform中的特定IP

192.168.5.4,192.168.5.5,192.168.5.6 ....等等

,所以我希望确保下面的IP在同一个故障域应该去。

说故障域0

192.168.5.4

192.168.5.7

192.168.5.10

说故障域1

192.168.5.5

192.168。 5.8

192.168.5.11

说故障域2

192.168.5.6

192.168.5.9

192.168.5.12

关系是(lastnumber%3)是一样的。 我怎么能做到这一点?

回答

0

您可以使用simple math interpolation像这样的东西:

variable "count" { 
    default = 10 
} 

resource "azurerm_network_interface" "test" { 
    name = "${format("VM%02d-NIC1", count.index + 1)}" 
    location = "West US" 
    resource_group_name = "myResourceGroup" 
    count = "${var.count}" 

    ip_configuration { 
     name = "${format("ipConfig-VM%02d-NIC1", count.index + 1)}" 
     subnet_id = "SubNet" 
     private_ip_address_allocation = "Static" 
     private_ip_address = "192.168.5.${count.index + 1}" 
    } 

    tags { 
     fault_domain = "${(count.index + 1) % 3}" 
    } 
} 

然后根据您的要求建立基础设施的其余部分并分配NIC给虚拟机:

resource "azurerm_virtual_machine" "test" { 
    count = "${var.count}" 
    name = "${format("VM%02-test", cound.index + 1)}" 
    location = "West US" 
    resource_group_name = "myResourceGroup" 
    network_interface_ids = ["${element(azurerm_network_interface.test, count.index).id}"] 
    vm_size = "Standard_A0" 
    ... 
}