Hi,
I have created a few VMs with public IP addresses without using count.
resource "azurerm_public_ip" "network-worker" {
name = "vm-public-ip-worker"
location = "${azurerm_resource_group.resource_group.location}"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
public_ip_address_allocation = "Dynamic"
idle_timeout_in_minutes = 30
}
resource "azurerm_public_ip" "network-web" {
name = "vm-public-ip-web"
location = "${azurerm_resource_group.resource_group.location}"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
public_ip_address_allocation = "Dynamic"
idle_timeout_in_minutes = 30
}
resource "azurerm_public_ip" "network-db" {
name = "vm-public-ip-db"
location = "${azurerm_resource_group.resource_group.location}"
resource_group_name = "${azurerm_resource_group.resource_group.name}"
public_ip_address_allocation = "Dynamic"
idle_timeout_in_minutes = 30
}
Now I'd like to print the public ips newline separated into a file. I know it can be achieved when using count with the following syntax:
resource "local_file" "inventory" {
content = "${format("%s\n", join("\n", azurerm_public_ip.network.*.ip_address))}"
filename = "inventory"
}
But since my VMs are named differently, I would need another approach. Preferably something in the lines of:
resource "local_file" "vms" {
content = "${format("%s\n", join("\n", azurerm_public_ip.*.ip_address))}"
filename = "inventory"
}
OR
resource "local_file" "vms" {
content = "${format("%s\n", join("\n", data.azurerm_public_ips.network.ip_addresses))}"
filename = "inventory"
}
Yet I haven't found a syntax that would work for this use case :(
This one is unfortunately too verbose to write out to a file with the "local_file" terraform provider.
output "public_ip_addresses" {
value = "${data.azurerm_public_ips.network.public_ips}"
}
Is there a good approach to list them out, without naming each explicitly? (like in the example below... because this list will grow over time and would really need dynamic generation)
content = "${format("%s\n%s\n%s\n", azurerm_public_ip.network-worker.ip_address, ...))}"