Murat ÖZDEMİR 720c79d460 Add Hetzner Cloud production infrastructure with multi-node support
- This commit introduces the Terraform configuration to provision a production environment on Hetzner Cloud, building on the existing test setup.
- Key improvements and new features include:
* **Multi-node clusters:** Scaling to 3-node Swarm application and database clusters for improved resilience.
* **High availability:** Utilizing a Hetzner Floating IP for the application entry point and `spread` placement groups for fault tolerance across physical hosts.
* **Enhanced network security:** Internal management services (RabbitMQ, APISIX, Prometheus, Grafana) are restricted to the application subnet, expected to be accessed via an internal reverse proxy (SWAG).
* **Internal database replication:** New firewall rules enable PostgreSQL replication and MongoDB replica set traffic within the database subnet.
* **Refined test environment:** Updates to align `test` configuration with the new `prod` structure, including a dedicated floating IP and adjusted firewall rules.
* **Configuration standardization:** Environment-specific details moved to `locals.tf` for clarity, with upgraded server types and migration to Rocky Linux as the base image.
- Updates were also made to the latest version of Terraform to ensure consistency in the documentation
2026-05-10 15:43:22 +03:00

72 lines
1.8 KiB
HCL

resource "hcloud_ssh_key" "admin" {
name = "${local.name_prefix}-admin-key"
public_key = file(var.admin_ssh_public_key_path)
}
resource "hcloud_server" "swarm" {
name = "iklim-app-01"
server_type = var.server_type_swarm
image = var.image
location = var.location
ssh_keys = [hcloud_ssh_key.admin.id]
placement_group_id = hcloud_placement_group.test_spread.id
labels = {
environment = local.environment
role = "swarm"
type = "service"
}
# prevent_destroy: Terraform'un sunucuyu kazara silmesini engeller.
# Kasitli silmek icin once bu bloku kaldir.
lifecycle {
prevent_destroy = true
}
}
resource "hcloud_server" "db" {
name = "iklim-db-01"
server_type = var.server_type_db
image = var.image
location = var.location
ssh_keys = [hcloud_ssh_key.admin.id]
placement_group_id = hcloud_placement_group.test_spread.id
labels = {
environment = local.environment
role = "db"
type = "db"
}
lifecycle {
prevent_destroy = true
}
}
# Ayri resource: firewall veya network degistiginde sunucu recreation tetiklenmez.
resource "hcloud_server_network" "swarm" {
server_id = hcloud_server.swarm.id
network_id = hcloud_network.main.id
ip = local.swarm_private_ip
depends_on = [hcloud_network_subnet.app]
}
resource "hcloud_server_network" "db" {
server_id = hcloud_server.db.id
network_id = hcloud_network.main.id
ip = local.db_private_ip
depends_on = [hcloud_network_subnet.db]
}
resource "hcloud_firewall_attachment" "swarm" {
firewall_id = hcloud_firewall.swarm.id
server_ids = [hcloud_server.swarm.id]
}
resource "hcloud_firewall_attachment" "db" {
firewall_id = hcloud_firewall.db.id
server_ids = [hcloud_server.db.id]
}