From 1e17d87b4f6a5b13daef7f25104ac2167fac900a Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 30 Dec 2025 12:30:52 -0500 Subject: [PATCH] feat: added server instances --- terraform/compute.tf | 22 ++++++++++++++++++++++ terraform/main.tf | 13 ------------- terraform/outputs.tf | 3 +++ terraform/variables.tf | 4 ++++ 4 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 terraform/outputs.tf diff --git a/terraform/compute.tf b/terraform/compute.tf index f4a1702..e62d770 100644 --- a/terraform/compute.tf +++ b/terraform/compute.tf @@ -17,6 +17,28 @@ resource "hcloud_server" "nat" { server_type = "cx23" placement_group_id = hcloud_placement_group.group.id ssh_keys = [hcloud_ssh_key.main.id] + + network { + network_id = hcloud_network.net.id + ip = local.nat-private-ip + } + + public_net { + ipv4_enabled = true + } } +// Private compute instances. +resource "hcloud_server" "server" { + for_each = local.servers + name = each.key + image = "debian-12" + server_type = "cx23" + placement_group_id = hcloud_placement_group.group.id + ssh_keys = [hcloud_ssh_key.main.id] + network { + network_id = hcloud_network.net.id + ip = each.value + } +} diff --git a/terraform/main.tf b/terraform/main.tf index e08744e..f27a19f 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -4,13 +4,6 @@ resource "hcloud_network" "net" { ip_range = local.net-cidr } -// Attach the NAT to the network. -resource "hcloud_server_network" "nat-to-net" { - server_id = hcloud_server.nat.id - network_id = hcloud_network.net.id - ip = local.nat-private-ip -} - // Provide internet to the private servers, by sending all internet traffic to // the NAT. resource "hcloud_network_route" "gateway" { @@ -18,9 +11,3 @@ resource "hcloud_network_route" "gateway" { destination = "0.0.0.0/0" gateway = local.nat-private-ip } - -// Give the NAT a public IP. -resource "hcloud_floating_ip" "master" { - type = "ipv4" - server_id = hcloud_server.nat.id -} diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..1355ac8 --- /dev/null +++ b/terraform/outputs.tf @@ -0,0 +1,3 @@ +output "nat-public-ip" { + value = hcloud_server.nat.ipv4_address +} diff --git a/terraform/variables.tf b/terraform/variables.tf index eb819c2..0820145 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -2,6 +2,10 @@ locals { net-cidr = "10.0.0.0/8" nat-private-ip = "10.0.1.5" + servers = { + Node0 = "10.0.2.0" + Node1 = "10.0.2.1" + } } variable "public_key_file" {