我想用teraaform做这些事情。我将像10一样同时创建多个vms。 我打算使用静态IP选项 所以,让我们说我的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 :(得分: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分配给您的VM:
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"
...
}