我正在使用terraform创建一个资源组。资源组具有具有ipv4和ipv6地址的NIC的虚拟机。我正在尝试创建一个具有ipv4、ipv6 ip地址的后端地址池的负载均衡器,我可以用ipv4创建后端池,但不能用ipv6创建后端池。我需要知道如何访问NIC的ipv6地址,以便在ip_address部件中调用它。
ip_address = azurerm_network_interface.vm-outside[count.index].private_ip_address中的某些内容需要更改,但不确定要更改什么。
如果我静态地添加一个ipv6地址,比如ip_address = "fd00:ab8:deca:4::4“,我可以创建它,我需要一种动态方式,因为我想要创建多个vm和ipv6地址。
需要知道如何动态地将ip_address指向网卡的辅助ipv6地址。
variable "instances" {
default = 2
description = "Number of instances"
}
resource "azurerm_network_interface" "vm-outside" {
depends_on = [azurerm_subnet.subnets]
name = "${var.prefix}-xxx%{if var.instances > 1}-${count.index}%{endif}"
count = var.instances
location = var.location
resource_group_name = local.rg_name
ip_configuration {
name = "xxx-ipv4%{if var.instances > 1}-${count.index}%{endif}"
subnet_id = azurerm_subnet.subnets["xxx"].id
private_ip_address_allocation = "Dynamic"
primary = true
}
ip_configuration {
name = "xxx-ipv6%{if var.instances > 1}-${count.index}%{endif}"
subnet_id = azurerm_subnet.subnets["xxx"].id
private_ip_address_allocation = "Dynamic"
private_ip_address_version = "IPv6"
}
}
resource "azurerm_lb_backend_address_pool_address" "backend-address-ipv4" {
count = var.instances > 1 ? var.instances : 0
name = "backend-address-%{if var.instances > 1}-${count.index}%{endif}"
backend_address_pool_id = azurerm_lb_backend_address_pool.backend-address-Pool[0].id
virtual_network_id = var.vn ? azurerm_virtual_network.vm[0].id : data.azurerm_virtual_network.vm[0].id
ip_address = azurerm_network_interface.vm-outside[count.index].private_ip_address
}
resource "azurerm_lb_backend_address_pool_address" "backend-address-ipv6" {
count = var.instances > 1 ? var.instances : 0
name = "backend-address-ipv6-%{if var.instances > 1}-${count.index}%{endif}"
backend_address_pool_id = azurerm_lb_backend_address_pool.backend-address-Pool[0].id
virtual_network_id = var.vn ? azurerm_virtual_network.vm[0].id : data.azurerm_virtual_network.vm[0].id
ip_address = azurerm_network_interface.vm-outside[count.index+1].private_ip_address
}我得到了以下错误:
count.index is 1
The given key does not identify an element in this collection value: the given index is greater than or equal to the length of the collection.发布于 2022-06-15 17:25:26
能够让它和这个陈述一起工作。多亏了Marko ip_address = azurerm_network_interface.vm-outside[count.index].private_ip_addresses[1]
https://stackoverflow.com/questions/72628605
复制相似问题