我有一个连接到三个 Docker 网络的容器化网络功能 (CNF):
...
ip_address = "172.17.0.3"
ip_prefix_length = 16
ipc_mode = "private"
log_driver = "json-file"
log_opts = {}
logs = false
max_retry_count = 0
memory = 4096
memory_swap = -1
must_run = true
name = "c-router-52"
network_data = [
{
gateway = "172.17.0.1"
ip_address = "172.17.0.3"
ip_prefix_length = 16
network_name = "bridge"
},
{
gateway = "172.31.0.1"
ip_address = "172.31.0.4"
ip_prefix_length = 16
network_name = "inside-net"
},
{
gateway = "172.30.0.1"
ip_address = "172.30.0.3"
ip_prefix_length = 16
network_name = "outside-net"
},
]
network_mode = "default"
...
我正在尝试获取“外网”IP 地址以用作另一个容器的输入。我这样指定:
${docker_container.c-router-52.network_data[2].ip_address}
当它是第三个元素时,它可以正常工作....但问题是 Terraform(或 Docker,两者之一)并不总是将“外部网络”作为第三个网络:(
有没有办法指定 [network_name="outside-net"] 而不是索引号?