kube-hetzner / terraform-hcloud-kube-hetzner

Optimized and Maintenance-free Kubernetes on Hetzner Cloud in one command!
MIT License
2.41k stars 372 forks source link

add control_plane_nodes and agent_nodes output #1461

Closed 0xch4z closed 2 months ago

0xch4z commented 3 months ago

This change adds new outputs control_plane_nodes and agent_nodes to output a list of objects forwarding all outputs from modules/host (ipv4_address, ipv6_address, private_ipv4_address, name and id).

Closes #1460


main.tf:

module "prod-us-east-1" {
    source = "../terraform-hcloud-kube-hetzner"

    control_plane_nodepools = [
        {
            name        = "control-plane",
            server_type = "cpx21",
            location    = "ash",
            count       = 3
            labels      = []
            taints      = []
        }
    ]

    agent_nodepools = [
        {
            name        = "worker",
            server_type = "cpx21",
            location    = "ash",
            count       = 3
            labels      = []
            taints      = []
        }
    ]

    # ...
}

output "nodes" {
  value = concat(module.prod-us-east-1.agent_nodes, module.prod-us-east-1.control_plane_nodes)
}

output:

module.prod-us-east-1.null_resource.kustomization: Creation complete after 53s [id=1408305325813632907]

Apply complete! Resources: 62 added, 0 changed, 0 destroyed.

Outputs:

kubeconfig = <sensitive>
nodes = [
  {
    "id" = "XXXXXXX"
    "ipv4_address" = "178.156.XXX.XXX"
    "ipv6_address" = "2a01:4ff:f0:XXXX::1"
    "name" = "k3s-worker-gnu"
    "private_ipv4_address" = "10.0.0.101"
  },
  {
    "id" = "XXXXXXX"
    "ipv4_address" = "5.161.XXX.XXX"
    "ipv6_address" = "2a01:4ff:f0:XXXX::1"
    "name" = "k3s-worker-wbu"
    "private_ipv4_address" = "10.0.0.102"
  },
  {
    "id" = "XXXXXXX"
    "ipv4_address" = "5.161.XXX.XXX"
    "ipv6_address" = "2a01:4ff:f0:XXXX::1"
    "name" = "k3s-worker-pag"
    "private_ipv4_address" = "10.0.0.103"
  },
  {
    "id" = "XXXXXXX"
    "ipv4_address" = "5.161.XXX.XXX"
    "ipv6_address" = "2a01:4ff:f0:XXXX::1"
    "name" = "k3s-control-plane-iqd"
    "private_ipv4_address" = "10.255.0.101"
  },
  {
    "id" = "XXXXXXX"
    "ipv4_address" = "5.161.XXX.XXX"
    "ipv6_address" = "2a01:4ff:f0:XXXX::1"
    "name" = "k3s-control-plane-tvx"
    "private_ipv4_address" = "10.255.0.102"
  },
  {
    "id" = "XXXXXXX"
    "ipv4_address" = "5.161.XXX.XXX"
    "ipv6_address" = "2a01:4ff:f0:XXXX::1"
    "name" = "k3s-control-plane-mng"
    "private_ipv4_address" = "10.255.0.103"
  },
]