Refactor: Rename swarm infrastructure components to app
This commit systematically updates all Terraform configurations, including resources, variables, and labels, to use the more generic `app` designation instead of `swarm`. This improves consistency and decouples the infrastructure naming from a specific container orchestration technology like Docker Swarm.
This commit is contained in:
parent
a25fa37aec
commit
58b6fdc605
@ -1,4 +1,4 @@
|
|||||||
resource "hcloud_firewall" "swarm" {
|
resource "hcloud_firewall" "app" {
|
||||||
name = "${local.name_prefix}-firewall-app"
|
name = "${local.name_prefix}-firewall-app"
|
||||||
|
|
||||||
rule {
|
rule {
|
||||||
@ -171,7 +171,7 @@ resource "hcloud_firewall" "swarm" {
|
|||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
environment = local.environment
|
environment = local.environment
|
||||||
role = "swarm"
|
role = "app"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,5 +14,5 @@ resource "hcloud_floating_ip" "app" {
|
|||||||
# Failover gerekirse manuel veya otomasyon ile baska app node'una tasinabilir.
|
# Failover gerekirse manuel veya otomasyon ile baska app node'una tasinabilir.
|
||||||
resource "hcloud_floating_ip_assignment" "app" {
|
resource "hcloud_floating_ip_assignment" "app" {
|
||||||
floating_ip_id = hcloud_floating_ip.app.id
|
floating_ip_id = hcloud_floating_ip.app.id
|
||||||
server_id = hcloud_server.swarm["iklim-app-01"].id
|
server_id = hcloud_server.app["iklim-app-01"].id
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ locals {
|
|||||||
hcloud_project = "iklim_prod"
|
hcloud_project = "iklim_prod"
|
||||||
name_prefix = "iklim-prod"
|
name_prefix = "iklim-prod"
|
||||||
|
|
||||||
swarm_private_ips = {
|
app_private_ips = {
|
||||||
"iklim-app-01" = "10.20.10.11"
|
"iklim-app-01" = "10.20.10.11"
|
||||||
"iklim-app-02" = "10.20.10.12"
|
"iklim-app-02" = "10.20.10.12"
|
||||||
"iklim-app-03" = "10.20.10.13"
|
"iklim-app-03" = "10.20.10.13"
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
output "ansible_inventory_yaml" {
|
output "ansible_inventory_yaml" {
|
||||||
description = "Ansible inventory in YAML format — write to ansible/inventory/generated/prod.yml"
|
description = "Ansible inventory in YAML format"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = yamlencode({
|
value = yamlencode({
|
||||||
all = {
|
all = {
|
||||||
children = {
|
children = {
|
||||||
swarm = {
|
app = {
|
||||||
hosts = {
|
hosts = {
|
||||||
for name, server in hcloud_server.swarm : name => {
|
for name, server in hcloud_server.app : name => {
|
||||||
ansible_host = server.ipv4_address
|
ansible_host = server.ipv4_address
|
||||||
private_ip = local.swarm_private_ips[name]
|
|
||||||
ansible_user = "root"
|
ansible_user = "root"
|
||||||
|
private_ip = local.app_private_ips[name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,8 +17,8 @@ output "ansible_inventory_yaml" {
|
|||||||
hosts = {
|
hosts = {
|
||||||
for name, server in hcloud_server.db : name => {
|
for name, server in hcloud_server.db : name => {
|
||||||
ansible_host = server.ipv4_address
|
ansible_host = server.ipv4_address
|
||||||
private_ip = local.db_private_ips[name]
|
|
||||||
ansible_user = "root"
|
ansible_user = "root"
|
||||||
|
private_ip = local.db_private_ips[name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ output "prod_private_ips" {
|
|||||||
description = "Private IPs assigned to prod nodes"
|
description = "Private IPs assigned to prod nodes"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = {
|
value = {
|
||||||
swarm = local.swarm_private_ips
|
app = local.app_private_ips
|
||||||
db = local.db_private_ips
|
db = local.db_private_ips
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,13 +40,13 @@ output "prod_public_ips" {
|
|||||||
description = "Public IPv4 addresses of prod nodes"
|
description = "Public IPv4 addresses of prod nodes"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = {
|
value = {
|
||||||
swarm = { for name, server in hcloud_server.swarm : name => server.ipv4_address }
|
app = { for name, server in hcloud_server.app : name => server.ipv4_address }
|
||||||
db = { for name, server in hcloud_server.db : name => server.ipv4_address }
|
db = { for name, server in hcloud_server.db : name => server.ipv4_address }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output "prod_floating_ip" {
|
output "prod_floating_ip" {
|
||||||
description = "Floating IP for prod swarm entry point — point DNS A records here"
|
description = "Floating IP for prod app entry point — point DNS A records here"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = hcloud_floating_ip.app.ip_address
|
value = hcloud_floating_ip.app.ip_address
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,11 @@ resource "hcloud_ssh_key" "admin" {
|
|||||||
public_key = file(var.admin_ssh_public_key_path)
|
public_key = file(var.admin_ssh_public_key_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_server" "swarm" {
|
resource "hcloud_server" "app" {
|
||||||
for_each = local.swarm_private_ips
|
for_each = local.app_private_ips
|
||||||
|
|
||||||
name = each.key
|
name = each.key
|
||||||
server_type = var.server_type_swarm
|
server_type = var.server_type_app
|
||||||
image = var.image
|
image = var.image
|
||||||
location = var.location
|
location = var.location
|
||||||
ssh_keys = [hcloud_ssh_key.admin.id]
|
ssh_keys = [hcloud_ssh_key.admin.id]
|
||||||
@ -15,7 +15,7 @@ resource "hcloud_server" "swarm" {
|
|||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
environment = local.environment
|
environment = local.environment
|
||||||
role = "swarm"
|
role = "app"
|
||||||
type = "service"
|
type = "service"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,10 +45,10 @@ resource "hcloud_server" "db" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_server_network" "swarm" {
|
resource "hcloud_server_network" "app" {
|
||||||
for_each = local.swarm_private_ips
|
for_each = local.app_private_ips
|
||||||
|
|
||||||
server_id = hcloud_server.swarm[each.key].id
|
server_id = hcloud_server.app[each.key].id
|
||||||
network_id = hcloud_network.main.id
|
network_id = hcloud_network.main.id
|
||||||
ip = each.value
|
ip = each.value
|
||||||
|
|
||||||
@ -65,9 +65,9 @@ resource "hcloud_server_network" "db" {
|
|||||||
depends_on = [hcloud_network_subnet.db]
|
depends_on = [hcloud_network_subnet.db]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_firewall_attachment" "swarm" {
|
resource "hcloud_firewall_attachment" "app" {
|
||||||
firewall_id = hcloud_firewall.swarm.id
|
firewall_id = hcloud_firewall.app.id
|
||||||
server_ids = [for s in hcloud_server.swarm : s.id]
|
server_ids = [for s in hcloud_server.app : s.id]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_firewall_attachment" "db" {
|
resource "hcloud_firewall_attachment" "db" {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
hcloud_token = "YOUR_HETZNER_PROD_PROJECT_API_TOKEN"
|
hcloud_token = "YOUR_HETZNER_PROD_PROJECT_API_TOKEN"
|
||||||
location = "fsn1"
|
location = "fsn1"
|
||||||
image = "rocky-10"
|
image = "rocky-10"
|
||||||
server_type_swarm = "cpx42"
|
server_type_app = "cpx42"
|
||||||
server_type_db = "cpx32"
|
server_type_db = "cpx32"
|
||||||
admin_ssh_public_key_path = "~/.ssh/id_ed25519.pub"
|
admin_ssh_public_key_path = "~/.ssh/id_ed25519.pub"
|
||||||
admin_allowed_cidrs = ["1.2.3.4/32", "5.6.7.8/32"]
|
admin_allowed_cidrs = ["1.2.3.4/32", "5.6.7.8/32"]
|
||||||
|
|||||||
@ -16,10 +16,10 @@ variable "image" {
|
|||||||
description = "Server image"
|
description = "Server image"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "server_type_swarm" {
|
variable "server_type_app" {
|
||||||
type = string
|
type = string
|
||||||
default = "cpx42"
|
default = "cpx42"
|
||||||
description = "Hetzner server type for Swarm nodes"
|
description = "Hetzner server type for App nodes"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "server_type_db" {
|
variable "server_type_db" {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
resource "hcloud_firewall" "swarm" {
|
resource "hcloud_firewall" "app" {
|
||||||
name = "${local.name_prefix}-firewall-app"
|
name = "${local.name_prefix}-firewall-app"
|
||||||
|
|
||||||
rule {
|
rule {
|
||||||
@ -171,7 +171,7 @@ resource "hcloud_firewall" "swarm" {
|
|||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
environment = local.environment
|
environment = local.environment
|
||||||
role = "swarm"
|
role = "app"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,5 +12,5 @@ resource "hcloud_floating_ip" "app" {
|
|||||||
|
|
||||||
resource "hcloud_floating_ip_assignment" "app" {
|
resource "hcloud_floating_ip_assignment" "app" {
|
||||||
floating_ip_id = hcloud_floating_ip.app.id
|
floating_ip_id = hcloud_floating_ip.app.id
|
||||||
server_id = hcloud_server.swarm.id
|
server_id = hcloud_server.app.id
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ locals {
|
|||||||
hcloud_project = "iklim_test"
|
hcloud_project = "iklim_test"
|
||||||
name_prefix = "iklim-test"
|
name_prefix = "iklim-test"
|
||||||
|
|
||||||
swarm_private_ip = "10.10.10.11"
|
app_private_ip = "10.10.10.11"
|
||||||
db_private_ip = "10.10.20.11"
|
db_private_ip = "10.10.20.11"
|
||||||
|
|
||||||
network_zone = "eu-central"
|
network_zone = "eu-central"
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
output "ansible_inventory_yaml" {
|
output "ansible_inventory_yaml" {
|
||||||
description = "Ansible inventory in YAML format — write to ansible/inventory/generated/test.yml"
|
description = "Ansible inventory in YAML format"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = yamlencode({
|
value = yamlencode({
|
||||||
all = {
|
all = {
|
||||||
children = {
|
children = {
|
||||||
swarm = {
|
app = {
|
||||||
hosts = {
|
hosts = {
|
||||||
(hcloud_server.swarm.name) = {
|
(hcloud_server.app.name) = {
|
||||||
ansible_host = hcloud_server.swarm.ipv4_address
|
ansible_host = hcloud_server.app.ipv4_address
|
||||||
private_ip = local.swarm_private_ip
|
|
||||||
ansible_user = "root"
|
ansible_user = "root"
|
||||||
|
private_ip = local.app_private_ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,8 +17,8 @@ output "ansible_inventory_yaml" {
|
|||||||
hosts = {
|
hosts = {
|
||||||
(hcloud_server.db.name) = {
|
(hcloud_server.db.name) = {
|
||||||
ansible_host = hcloud_server.db.ipv4_address
|
ansible_host = hcloud_server.db.ipv4_address
|
||||||
private_ip = local.db_private_ip
|
|
||||||
ansible_user = "root"
|
ansible_user = "root"
|
||||||
|
private_ip = local.db_private_ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ output "test_private_ips" {
|
|||||||
description = "Private IPs assigned to test nodes"
|
description = "Private IPs assigned to test nodes"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = {
|
value = {
|
||||||
swarm_01 = local.swarm_private_ip
|
app_01 = local.app_private_ip
|
||||||
db_01 = local.db_private_ip
|
db_01 = local.db_private_ip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,13 +40,13 @@ output "test_public_ips" {
|
|||||||
description = "Public IPv4 addresses of test nodes"
|
description = "Public IPv4 addresses of test nodes"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = {
|
value = {
|
||||||
swarm_01 = hcloud_server.swarm.ipv4_address
|
app_01 = hcloud_server.app.ipv4_address
|
||||||
db_01 = hcloud_server.db.ipv4_address
|
db_01 = hcloud_server.db.ipv4_address
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output "test_floating_ip" {
|
output "test_floating_ip" {
|
||||||
description = "Floating IP for test app entry point — point DNS A records here"
|
description = "Floating IP assigned to the app entry point"
|
||||||
sensitive = false
|
sensitive = false
|
||||||
value = hcloud_floating_ip.app.ip_address
|
value = hcloud_floating_ip.app.ip_address
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,9 +3,9 @@ resource "hcloud_ssh_key" "admin" {
|
|||||||
public_key = file(var.admin_ssh_public_key_path)
|
public_key = file(var.admin_ssh_public_key_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_server" "swarm" {
|
resource "hcloud_server" "app" {
|
||||||
name = "iklim-app-01"
|
name = "iklim-app-01"
|
||||||
server_type = var.server_type_swarm
|
server_type = var.server_type_app
|
||||||
image = var.image
|
image = var.image
|
||||||
location = var.location
|
location = var.location
|
||||||
ssh_keys = [hcloud_ssh_key.admin.id]
|
ssh_keys = [hcloud_ssh_key.admin.id]
|
||||||
@ -13,7 +13,7 @@ resource "hcloud_server" "swarm" {
|
|||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
environment = local.environment
|
environment = local.environment
|
||||||
role = "swarm"
|
role = "app"
|
||||||
type = "service"
|
type = "service"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +44,10 @@ resource "hcloud_server" "db" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Ayri resource: firewall veya network degistiginde sunucu recreation tetiklenmez.
|
# Ayri resource: firewall veya network degistiginde sunucu recreation tetiklenmez.
|
||||||
resource "hcloud_server_network" "swarm" {
|
resource "hcloud_server_network" "app" {
|
||||||
server_id = hcloud_server.swarm.id
|
server_id = hcloud_server.app.id
|
||||||
network_id = hcloud_network.main.id
|
network_id = hcloud_network.main.id
|
||||||
ip = local.swarm_private_ip
|
ip = local.app_private_ip
|
||||||
|
|
||||||
depends_on = [hcloud_network_subnet.app]
|
depends_on = [hcloud_network_subnet.app]
|
||||||
}
|
}
|
||||||
@ -60,9 +60,9 @@ resource "hcloud_server_network" "db" {
|
|||||||
depends_on = [hcloud_network_subnet.db]
|
depends_on = [hcloud_network_subnet.db]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_firewall_attachment" "swarm" {
|
resource "hcloud_firewall_attachment" "app" {
|
||||||
firewall_id = hcloud_firewall.swarm.id
|
firewall_id = hcloud_firewall.app.id
|
||||||
server_ids = [hcloud_server.swarm.id]
|
server_ids = [hcloud_server.app.id]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_firewall_attachment" "db" {
|
resource "hcloud_firewall_attachment" "db" {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
hcloud_token = "YOUR_HETZNER_TEST_PROJECT_API_TOKEN"
|
hcloud_token = "YOUR_HETZNER_TEST_PROJECT_API_TOKEN"
|
||||||
location = "fsn1"
|
location = "fsn1"
|
||||||
image = "rocky-10"
|
image = "rocky-10"
|
||||||
server_type_swarm = "cpx42"
|
server_type_app = "cpx42"
|
||||||
server_type_db = "cpx42"
|
server_type_db = "cpx42"
|
||||||
admin_ssh_public_key_path = "~/.ssh/id_ed25519.pub"
|
admin_ssh_public_key_path = "~/.ssh/id_ed25519.pub"
|
||||||
admin_allowed_cidrs = ["1.2.3.4/32", "5.6.7.8/32"]
|
admin_allowed_cidrs = ["1.2.3.4/32", "5.6.7.8/32"]
|
||||||
|
|||||||
@ -16,10 +16,10 @@ variable "image" {
|
|||||||
description = "Server image"
|
description = "Server image"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "server_type_swarm" {
|
variable "server_type_app" {
|
||||||
type = string
|
type = string
|
||||||
default = "cpx42"
|
default = "cpx42"
|
||||||
description = "Hetzner server type for the Swarm node"
|
description = "Hetzner server type for the App node"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "server_type_db" {
|
variable "server_type_db" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user