您可以使用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"
...
}