当网卡有ipv4和ipv6地址时,azurerm_lb_backend_address_pool_address中的 i



我正在使用terraform创建一个资源组。资源组中有一个虚拟机,其网卡地址为ipv4和ipv6。我试图创建一个负载均衡器后端地址池有ipv4,ipv6的ip地址。我能够创建后端池与ipv4,但不能创建与ipv6。我需要知道如何访问网卡的ipv6地址,以便我可以在ip_address部分调用它。

ip_address = azurerm_network_interface.vm-outside[count.index].private_ip_address中的某些内容需要更改,但不确定要更改什么

如果我静态添加ipv6地址ip_address = "fd00:ab8:deca:4::4"我可以创建它,我需要一个动态的方式,因为我想创建多个虚拟机和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.

可以使用这个语句。感谢Markoip_address = azurerm_network_interface.vm-outside[count.index].private_ip_addresses[1]

最新更新