首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当网卡有ipv6和ipv6地址时,ipv4地址在ipv6中

当网卡有ipv6和ipv6地址时,ipv4地址在ipv6中
EN

Stack Overflow用户
提问于 2022-06-15 09:03:00
回答 1查看 84关注 0票数 0

我正在使用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地址。

代码语言:javascript
复制
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
}

我得到了以下错误:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-15 17:25:26

能够让它和这个陈述一起工作。多亏了Marko ip_address = azurerm_network_interface.vm-outside[count.index].private_ip_addresses[1]

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72628605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档