windowws
windowws

Reputation: 377

Terraform template with multiple IPs for a same variable

I have a terraform output like this

output  "servers_private_ip"{
    value = azurerm_linux_virtual_machine.myservers_vm.*.private_ip_address
}

servers_private_ip = [
  "10.0.2.7",
  "10.0.2.5",
  "10.0.2.8",
]

I need to render these as below into a variable that can be used in a .tpl file

10.0.2.7:1245,10.0.2.5:1245,10.0.2.8:1245

i tried it like this

tpl_variable = azurerm_linux_virtual_machine.myservers_vm.*.private_ip_address

But i am not sure how can i append the port number i want for each ip in this,Any help on this would be appreciated.

Upvotes: 0

Views: 943

Answers (1)

Max Ivanov
Max Ivanov

Reputation: 6591

How about this?

join the list items where each item has port appended:

tpl_variable = join(",", [for ip in azurerm_linux_virtual_machine.myservers_vm.*.private_ip_address: "${ip}:1245"])

Upvotes: 1

Related Questions