I have a module code to deploy a server, with a dynamic block for networks, shown here
resource "hcloud_server" "this" {
count = var.instance_count
name = "${local.instance_prefix}.${var.instance_name}${format("%02d", count.index + 1)}"
image = data.hcloud_image.image.id
server_type = var.flavour
datacenter = var.datacenter
ssh_keys = var.sshkeys
placement_group_id = hcloud_placement_group.this.id
labels = local.labels_default
firewall_ids = var.firewall_ids
lifecycle {
ignore_changes = [
ssh_keys,
image,
]
}
public_net {
ipv4_enabled = var.public_ipv4
ipv6_enabled = var.public_ipv6
}
dynamic "network" {
for_each = var.network
content {
network_id = lookup(network.value, "network_id")
ip = lookup(network.value, "private_ip", null)
# https://github.com/hetznercloud/terraform-provider-hcloud/issues/650#issuecomment-1497160625
alias_ips = []
}
}
}
According to the documentation the network
block has an attribute called ip which holds the assigned IP, see https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/resources/server#network
I want to access this private IP in my module output, but I cant get there. My output now looks like this
output "private_ip" {
description = "List with public IPv4 IPs of the instances"
value = hcloud_server.this.*.network[*].ip
}
and produces the following error
╷
│ Error: Unsupported attribute
│
│ on .terraform/modules/testserver/outputs.tf line 18, in output "private_ip":
│ 18: value = hcloud_server.this.*.network[*].ip
│
│ Can't access attributes on a set of objects. Did you mean to access an attribute across all elements of the set?
How can I access the ip atttribute in my output, ideally combined with the instance name?
I tried to play around with *
and [count.index]
but I didnt get there.
thanks for helping!!!