Files
workshop/aula-08/outputs.tf
Allyson de Paula aa2bcfce46 aula-07 e aula-08: Cluster Talos HA na Hetzner com Autoscaler
aula-07: Criação de imagem Talos customizada na Hetzner Cloud
- Usa Talos Factory para gerar imagem ARM64/AMD64
- Inclui extensões: qemu-guest-agent, hcloud

aula-08: Provisionamento de cluster Kubernetes Talos via OpenTofu
- 3 Control Planes em HA (CAX11 ARM64)
- 1 Worker Node (CAX11 ARM64)
- Rede privada, Floating IP, Firewall
- Cluster Autoscaler para Hetzner (0-5 workers extras)
- Setup interativo com validação de pré-requisitos
- Custo estimado: ~€18/mês (base)

Também inclui:
- .gitignore para ignorar arquivos sensíveis
- CLAUDE.md com instruções do projeto
2025-12-27 07:12:58 -03:00

154 lines
4.4 KiB
HCL

############################################################
# Outputs for Hetzner Talos Kubernetes Cluster
############################################################
# Cluster Information
output "cluster_name" {
description = "The name of the Kubernetes cluster"
value = local.cluster_name
}
output "cluster_id" {
description = "The unique identifier for the cluster"
value = random_string.cluster_id.result
}
# Network Information
output "network_id" {
description = "The ID of the cluster's private network"
value = hcloud_network.cluster.id
}
output "network_cidr" {
description = "The CIDR range of the cluster network"
value = hcloud_network_subnet.cluster.ip_range
}
# Control Plane Information
output "control_plane_ip" {
description = "Public IP address of the control plane"
value = hcloud_floating_ip.control_plane.ip_address
}
output "control_plane_private_ips" {
description = "Private IP addresses of control plane nodes"
value = [for cp in hcloud_server_network.control_plane : cp.ip]
}
output "control_plane_ids" {
description = "Server IDs of control plane nodes"
value = [for cp in hcloud_server.control_plane : cp.id]
}
# Worker Nodes Information
output "worker_ips" {
description = "Public IP addresses of worker nodes"
value = [for w in hcloud_server.worker : w.ipv4_address]
}
output "worker_private_ips" {
description = "Private IP addresses of worker nodes"
value = [for w in hcloud_server_network.worker : w.ip]
}
output "worker_ids" {
description = "Server IDs of worker nodes"
value = [for w in hcloud_server.worker : w.id]
}
# Kubernetes Access
output "kubeconfig_path" {
description = "Path to the generated kubeconfig file"
value = local_sensitive_file.kubeconfig.filename
}
output "talosconfig_path" {
description = "Path to the generated talosconfig file"
value = local_sensitive_file.talosconfig.filename
}
# API Endpoints
output "kubernetes_api_endpoint" {
description = "Kubernetes API server endpoint"
value = "https://${hcloud_floating_ip.control_plane.ip_address}:6443"
}
output "talos_api_endpoint" {
description = "Talos API endpoint for management"
value = "https://${hcloud_floating_ip.control_plane.ip_address}:50000"
}
# Cost Information
output "estimated_monthly_cost" {
description = "Estimated monthly cost for the infrastructure (EUR)"
value = {
control_plane = 3 * 3.79 # 3x CAX11
worker = 1 * 3.79 # 1x CAX11
floating_ip = 3.00 # Floating IPv4
total = (4 * 3.79) + 3.00 # ~€18.16
}
}
# Connection Instructions
output "connection_instructions" {
description = "Instructions for connecting to the cluster"
value = <<-EOT
====================================
Kubernetes Cluster Ready!
====================================
1. Configure kubectl:
export KUBECONFIG=${local_sensitive_file.kubeconfig.filename}
kubectl get nodes
2. Configure talosctl:
export TALOSCONFIG=${local_sensitive_file.talosconfig.filename}
talosctl --nodes ${hcloud_floating_ip.control_plane.ip_address} health
3. Access Kubernetes API:
${"https://${hcloud_floating_ip.control_plane.ip_address}:6443"}
4. Nodes:
Control Plane: 3x CAX11 (ARM64)
Workers: 1x CAX11 (ARM64)
5. Total Monthly Cost: ~€18/month
====================================
EOT
}
# Cluster Autoscaler Configuration
output "autoscaler_worker_config" {
description = "Worker machine config for cluster autoscaler (base64)"
value = base64encode(data.talos_machine_configuration.worker[0].machine_configuration)
sensitive = true
}
output "autoscaler_image_id" {
description = "Talos image ID for cluster autoscaler"
value = var.talos_image_id
}
# Resource Labels
output "resource_labels" {
description = "Labels applied to all resources"
value = local.common_labels
}
# Firewall Information
output "firewall_id" {
description = "ID of the firewall protecting the cluster"
value = hcloud_firewall.cluster.id
}
# SSH Key Information (for autoscaler)
output "ssh_key_name" {
description = "Name of the SSH key used by the cluster"
value = length(local.ssh_key_matches) > 0 ? [
for key in data.hcloud_ssh_keys.all.ssh_keys : key.name
if key.id == local.ssh_key_matches[0]
][0] : "${local.cluster_name}-admin"
}