I'm starting to use Terraform (0.12) with different types of servers, each associated to a different image. I'm trying to simply output all private IP (I don't know the number before runtime) but can't find a simple way to do it (I found a more complicated one).
I'm trying TF on scaleway provider and I have some servers declaration like this (simplified)
# INPUT
variable "srv1" {
type = number
default = 0
}
variable "srv2" {
type = number
default = 0
}
# IMAGES
data "scaleway_instance_image" "srv1" {
name = "srv1"
}
data "scaleway_instance_image" "srv2" {
name = "srv2"
}
# SERVERS
resource "scaleway_instance_server" "srv1" {
name = "srv1_${count.index}"
image = data.scaleway_instance_image.srv1.id
count = var.srv1
}
resource "scaleway_instance_server" "srv2" {
name = "srv2_${count.index}"
image = data.scaleway_instance_image.srv2.id
count = var.srv2
}
To output private IP from all servers, this is what I do
# OUTPUT
output "srv1_private_ips" {
value = ["${scaleway_instance_server.srv1.*.private_ip}"]
}
output "srv2_private_ips" {
value = ["${scaleway_instance_server.srv2.*.private_ip}"]
}
It works but I need to create an output
section for each server type. I would like to have the option
- to loop over a list of server types and output all IPs in one output. Didn't find how
- to just output all
scaleway_instance_server.*.*.private_ip
but the double wildcard seems not possible
Any help appreciated.