feat: added server instances
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
3
terraform/outputs.tf
Normal file
3
terraform/outputs.tf
Normal file
@@ -0,0 +1,3 @@
|
||||
output "nat-public-ip" {
|
||||
value = hcloud_server.nat.ipv4_address
|
||||
}
|
||||
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user