我想将我的Azure VM的外部和内部IP地址以script.py external1,internal1 external2,internal2 external3,internal3
的格式输入到Python脚本中,例如script.py 54.120.31.31,192.168.0.1 54.32.13.14,192.168.0.2 54.33.16.19,192.168.0.3
。
我可以使用以下命令获得所需的输出,只是格式不正确:
output "inventory" {
value = "${
formatlist(
"%s,%s",
azurerm_public_ip.main.*.ip_address,
azurerm_network_interface.main.*.private_ip_address
)
}"
}
是否可以将这些列表合并为所需的输出格式?
答案 0 :(得分:1)
您很亲密:
output "inventory" {
value = "${
join(
" ",
formatlist(
"%s,%s",
azurerm_public_ip.main.*.ip_address,
azurerm_network_interface.main.*.private_ip_address
)
)
}"
}
示例:
output "inventory" {
value = "${
join(
" ",
formatlist(
"%s,%s",
list("1", "2", "3"),
list("a", "b", "c")
)
)
}"
}
> terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
inventory = 1,a 2,b 3,c