output "ansible_inventory_yaml" {
  description = "Ansible inventory in YAML format"
  sensitive   = false
  value = yamlencode({
    all = {
      children = {
        app = {
          hosts = {
            for name, server in hcloud_server.app : name => merge(
              {
                ansible_host = server.ipv4_address
                ansible_user = "root"
                private_ip   = local.app_private_ips[name]
              },
              name == "iklim-app-01" ? { hetzner_floating_ip = hcloud_floating_ip.app.ip_address } : {}
            )
          }
        }
        db = {
          hosts = {
            for name, server in hcloud_server.db : name => {
              ansible_host = server.ipv4_address
              ansible_user = "root"
              private_ip   = local.db_private_ips[name]
            }
          }
        }
      }
    }
  })
}

output "prod_private_ips" {
  description = "Private IPs assigned to prod nodes"
  sensitive   = false
  value = {
    app = local.app_private_ips
    db    = local.db_private_ips
  }
}

output "prod_public_ips" {
  description = "Public IPv4 addresses of prod nodes"
  sensitive   = false
  value = {
    app = { for name, server in hcloud_server.app : name => server.ipv4_address }
    db    = { for name, server in hcloud_server.db : name => server.ipv4_address }
  }
}

output "prod_floating_ip" {
  description = "Floating IP for prod app entry point — point DNS A records here"
  sensitive   = false
  value       = hcloud_floating_ip.app.ip_address
}
