我想用teraaform做这些事情。我将像10一样同时创建多个VM。我要使用静态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)是相同的。我该如何实现?
您可以使用这样的东西使用简单的数学插值:
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分配给您的VMS:
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"
...
}